Skip to content
Back

Invalid token passed in the request

  • 0
  • Self Hosted
  • Web
djcali
14 Feb, 2026, 04:02

Hello, I have an issue using updateMagicURLSession. I send the email using sendMagicLink, which works fine. When i click the link in the email i get the invalid token passed in the request. What is really weird is when i refresh the browser everything works, just not directly clicking the email. I am using Svelte with ssr and doing this server side.

Here is the code. Not sure why this is happening. because i checked everything and i do get a session when i view the cookies in the browser inspector.

TL;DR
Issue: Invalid token error when clicking magic link in email, but works after browser refresh. Solution: The invalid token error may be due to the session not being fully initialized when directly clicking the link. Ensure the session client is correctly set up and try introducing a delay before handling the session after clicking the magic link. Refreshing the browser seems to give enough time for session initialization, resolving the issue temporarily.
djcali
14 Feb, 2026, 04:04

I have a separate file for creating the session client:

TypeScript
    const client = new Client()
        .setEndpoint(PRIVATE_APPWRITE_ENDPOINT) // Your endpoint
        .setProject(PRIVATE_APPWRITE_PROJECT)
        .setKey(PRIVATE_APPWRITE_KEY); // API key for admin tasks
    return client;
}

export function createSessionClient() {
    const client = new Client()
        .setEndpoint(PRIVATE_APPWRITE_ENDPOINT) // Same endpoint
        .setProject(PRIVATE_APPWRITE_PROJECT); // No API key here
    return client;
}```
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