Appwrite version: 1.6.0 Client version (16.0.2)
Hi, we are having some issues with sessions currently. We would like active users to stay logged in but they are currently getting logged out which is problematic for these users.
I'm currently testing with a session length of 2 minutes. When the user opens the app we extend their session by doing this:
try {
const account = new Account(client);
await account.updateSession('current');
} catch (error) {
const err = error as { code?: number };
if (err.code === 401) {
handleSessionError(err.code);
}
}
This works and I can see within the Appwrite console that the expire time is extended. I've also debugged this by doing:
const session = await account.getSession('current');
and then logging the session.
Still the session gets invalidated based on the original expire time. So the time of which the session was created. When the original expire time is reached I get an error when doing:
const client = getClient(apiEndpoint, projectId);
const account = new Account(client);
try {
await account.get();
} catch (e) {
console.log('baseQuery error getting account', e);
}
In the logs I then see:
LOG baseQuery error getting account [AppwriteException: User (role: guests) missing scope (account)]
The session is created from a secret from our custom backend server.
await account.createSession(configUser.userId, configUser.authSecret);
Note: I've made sure that the client is only created once in memory, it's then reused so we are not creating a new client multiple times.
Any help/insights would be greatly appreciated!
getSession() endpoint simply gets the session, meaning it's not renewing it.
The only way to renew it is creating a new session with email/password, etc.
What's your specific use case?
Hey, thank you for the quick response! I'm trying to extend the session by calling updateSession, not getSession. From my understanding this extends the current session. See method in docs: https://appwrite.io/docs/references/1.6.x/client-react-native/account#updateSession
When I use this it does change the expire time of the current session as expected but I am still logged out based on the original expire time
I have a diagram to show what is currently happening. It shows how our frontend interacts with Appwrite. Hopefully this can give more insights
I did also look into the Appwrite implementation of updateSession but I'm not too familiar with PHP so I couldn't figure it out. Would anyone be able to help me with this issue?
I am having the same thing as far as I can tell also with a React Native app. It doesn't seem to properly update the session even though I see the expiry time increase, the user is still logged out after the initial login/session creation (same as the diagram). Can anyone help? Does anyone have any ideas about what is going wrong?
Recommended threads
- Unable to init function via cli
Hello! I have created a new self hosted instance of appwrite 1.9.6 and have connected to that insatnce with the cli 27.2.0 that was released a few hours ago. Wh...
- Appwrite-injected variables are not avai...
I am using rust-1.83 as a runtime and try to access APPWRITE_FUNCTION_API_ENDPOINT or APPWRITE_FUNCTION_API_KEY during runtime. Both are not set during my execu...
- OAuth Missing redirect URL
Hello all, on a Flutter mobile app with latest Appwrite dependency (25.4.0) I always got "Missing redirect URL" - "Your OAuth login flow is missing a proper red...