Web Developer
If not, how can I verify the emails of users which would be registering using email otp?
Votes
0
Replies
10
Participants
Unknown
Messages
11
Web Developer
If not, how can I verify the emails of users which would be registering using email otp?
OTP is the secret, so it should be fine.
Web Developer
If that's the case, then why am I getting these error?
can you show some relevant code?
sdk versions would be good too in the details.
Web Developer
`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 };
}
};`
Web Developer
idk about sdk version but I am using appwrite 14.0.1
aah I see. My bad, you should be able to directly create a session. See - https://appwrite.io/docs/products/auth/email-otp
Web Developer
It means there is no way to verify a user through otp login?
looking at the source, once the session is created via magic-url or otp, the email should be marked as verified.
Web Developer
ooh, if that's the case. It would be nice!