Skip to content
Back

Is there a way to use OTP as a secret in the updateverification().

  • 0
  • Web
Hashim
24 Nov, 2024, 12:36

If not, how can I verify the emails of users which would be registering using email otp?

TL;DR
Developers are discussing using OTP as a secret in `updateVerification()` but are unsure if it is possible. They link to documentation for creating a session and share relevant code snippets. The main question revolves around verifying user emails using email OTP during registration.
darShan
24 Nov, 2024, 12:38

OTP is the secret, so it should be fine.

Hashim
24 Nov, 2024, 12:53

If that's the case, then why am I getting these error?

darShan
24 Nov, 2024, 12:54

can you show some relevant code?

darShan
24 Nov, 2024, 12:54

sdk versions would be good too in the details.

Hashim
24 Nov, 2024, 12:55

`export const register = async (email, password, name) => { try { const user = await account.create("unique()", email, password, name); if (user) { // Automatically log in after registration account.createEmailToken(ID.unique(), email, true).then( function (response) { console.log("Success sending otp"); // Success return response; }, function (error) { console.log("Failure sending otp", error); // Failure } ); // const session = await account.createSession(user.$id, secret); secret is the otp return { success: true, // data: session.data, emailVerification: user.emailVerification, userId: user.$id, // Return userId for OTP verification }; } return { success: false, error: "Registration failed" }; } catch (error) { console.error("Registration error:", error); return { success: false, error: error.message }; } };

export const verifyOTP = async (userId, secret) => { console.log("userId", userId, "\nOTP: ", secret); try { const response = await account.updateVerification(userId, secret); //I think it doesn't works with the otp response.then( function (response) { console.log("Verification was successful! \n", response); // Success }, function (error) { console.log("there was some error verifying the user \n", error); // Failure } ); return { success: true, data: response }; } catch (error) { console.error("OTP verification error:", error); return { success: false, error: error.message }; } };`

Hashim
24 Nov, 2024, 12:56

idk about sdk version but I am using appwrite 14.0.1

darShan
24 Nov, 2024, 12:56

aah I see. My bad, you should be able to directly create a session. See - https://appwrite.io/docs/products/auth/email-otp

Hashim
24 Nov, 2024, 12:57

It means there is no way to verify a user through otp login?

darShan
24 Nov, 2024, 12:59

looking at the source, once the session is created via magic-url or otp, the email should be marked as verified.

Hashim
24 Nov, 2024, 13:00

ooh, if that's the case. It would be nice!

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more