Skip to content
Back

Failed to verify JWT. Invalid token: Expired

  • 0
  • Functions
loremuser
15 Jul, 2025, 05:14

Hi

I am trying to call a function from my mobile app, but I am receiving "Invalid token expired."

My code looks more or less like this

TypeScript
// from my app
functions.createExecution(
  "import-function",
  JSON.stringify(data),
  true,
  "/",
  ExecutionMethod.POST);
TypeScript
// my function
import { Client, Databases, ID } from "node-appwrite";

export default async ({ req, res, log, error }) => {
    const client = new Client().setProject(process.env.APPWRITE_PROJECT_ID);

    if (req.headers["x-appwrite-user-jwt"]) {
        client.setJWT(req.headers["x-appwrite-user-jwt"]);
    } else {
        return res.json(
            {
                error:
                    "Access denied: This function requires authentication. Please sign in to continue.",
            },
            401,
        );
    }
  // rest
}

Here more details about my code: https://jumpshare.com/s/60JUJtYCBY0F2TNsuwhH

I don't even receive 401, but I receive a 500 status code.

So, my question is: Do I send/implement something else from my app/function ?

Thanks

TL;DR
Issue: Developer is getting "Invalid token expired" error when trying to call a function from their mobile app. The code from the mobile app includes creating an execution and passing data, while the function code initializes a client, checks for a JWT token, and returns an error message if not valid. Solution: The developer needs to regenerate the JWT token from the app side and ensure it is valid. The error suggests the token is expired or incorrect. To avoid unexpected 500 errors and properly authenticate, verify the JWT token mechanism and check for token validity before making the call.
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