Skip to content
Back

[SOLVED] Invalid token passed in the request.

  • 0
  • Web
  • Cloud
Chirag Aggarwal
4 Jan, 2025, 10:27

This is my code:

TypeScript
const client = new Client()
    .setEndpoint(endpoint)  
    .setProject(projectId)
    .setKey(apiKey);

const account = new Account(client);
const token = await account.createPhoneToken(ID.unique(), '+999999999');
console.log(token);
const session = await account.createSession(token.userId, token.secret);

console.log(session);

and i keep getting this error, which means the token passed is wrong. but this is the output i am getting from token:

TypeScript
{
  '$id': '67790ca497ccd684a12e',
  '$createdAt': '2025-01-04T10:25:40.622+00:00',
  userId: '67790a6f000cd0c04e96',
  secret: 'eyJpZCI6IjY3NzkwYTZmMDAwY2QwYzA0ZTk2Iiwic2VjcmV0IjoiMDAwMDAwIn0=',
  expire: '2025-01-04T10:40:40.621+00:00',
  phrase: ''
}
TL;DR
Developers confused token secret with SMS secret in their request. They should use the SMS code in `createSession`. The issue was resolved by using the correct secret.
Darshan Pandya
4 Jan, 2025, 10:39

I don't think it's supposed to be token.secret in createSession. It's supposed to be the SMS Code. Ref - https://x.com/appwrite/status/1834545614811472026

Darshan Pandya
4 Jan, 2025, 10:40

also, why Server SDK here with Key?

Chirag Aggarwal
4 Jan, 2025, 10:43

to get secret, otherwise it would be blank

Chirag Aggarwal
4 Jan, 2025, 10:43

and shouldnt user be able to signin without the sms code, and being unverified

Chirag Aggarwal
4 Jan, 2025, 10:44

that worked! thanks

Chirag Aggarwal
4 Jan, 2025, 10:44

i got confused between token secret and sms secret i guess 😅

Chirag Aggarwal
4 Jan, 2025, 10:45

[SOLVED] Invalid token passed in the request.

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