Skip to content
Back

Email OTP verification error: Invalid token passed in the request

  • 0
  • Android
  • Auth
  • Apple
  • Cloud
  • React Native
AjayLs
15 Feb, 2025, 22:34

Hello everyone, I have seen a few related posts about this but nothing related to react native. I am using email OTP to create an account. I provide an email and I get a 6-digit code. I use this code as the secret to be passed in updateVerification() to create a session but I get this error "Invalid token passed in the request." I have reviewed the documentation and, although it does not specify what the secret is, I think is obvious it should be that 6-digit number.

NOTE: the userId is extracted from the result value where the function is called.

export const sendVerification = async (email) => { try { const result = await account.createEmailToken( ID.unique(), email );

TypeScript
    return result;
} catch (error) {
    console.error("Error sending email:", error);
    throw new Error("Failed to send email.");
}

};

export const verifyCode = async (id, code) => {

TypeScript
try {
    const session = await account.updateVerification(
        id,
        code
    );

    return session;
} catch (error) {
    console.error("Error validating token:", error);
    throw new Error("Failed to validate token.");
}

};

TL;DR
Developers are encountering an "Invalid token passed in the request" error while using email OTP for account creation in a React Native app. The issue lies in passing the 6-digit code as the secret in updateVerification(). The proper solution is to use the code generated from the email OTP as the token.
Steven
15 Feb, 2025, 22:41

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting).

Steven
15 Feb, 2025, 22:41

Update verification is used with a different method

Steven
15 Feb, 2025, 22:42

Did you read the docs on email OTP auth? https://appwrite.io/docs/products/auth/email-otp

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