loremuserOriginal post
Web Developer
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 appfunctions.createExecution( "import-function", JSON.stringify(data), true, "/", ExecutionMethod.POST);TypeScript
// my functionimport { 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
Summary
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.