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.Recommended threads
- After assigning a domain to my Dart func...
I’ve attached the images. Could anyone please explain how this execution is being performed?
- I can't UNPAUSE my project with the free...
I received an email notifying me that my project had been paused due to inactivity, and the email included a link to "Restore project." However, that button red...
- Error trying to deploy functions from CL...
✗ Error • on-auth-create (6a00b2ab000c9ce2949b) • Server Error ✗ Error: No functions were pushed. Prject ID: 69ffe0270033a4ac420a