Back

JWT's and Session expire after 15 minutes (frontend)

  • 0
  • Self Hosted
  • Auth
  • Web
  • REST API
Lucas
11 Jan, 2025, 00:55

I’m using Appwrite for my web app and noticing that after ~15 minutes, my user session suddenly expires—calls like account.get() start returning 401 Unauthorized.

Here’s what I’ve confirmed so far:

Short-Lived JWT: I’m aware Appwrite’s JWT has a 15-minute expiry, but even if I try account.createJWT() after 15 minutes, it fails because the entire session is gone.

Session Cookie: Looking in the browser, my app’s session cookie is set to expire a year in the future, yet Appwrite still terminates the session around the 15-minute mark.

Has anyone dealt with this mismatch where the cookie’s “Expires” date is far in the future, but Appwrite ends the session after ~15 minutes anyway?

How can I configure (or refresh) the session so it remains valid beyond 15 minutes without forcing the user to re-log in?

my edge case I'm running into is when the user who wandered around the web app successfully steps away for 15+ minutes then comes back, and clicks a button that sends a request to my backend (with JWT) has that request fail.

the only trick I found to make it work again is to manually refresh the whole page/webapp at which point everything works again.

TL;DR
Issue: User sessions in web app using Appwrite expire after 15 minutes even though session cookie is set to expire in a year. Calls like account.get() return 401 Unauthorized. Manually refreshing the page fixes the problem. Solution: This issue arises due to Appwrite's JWT expiry. To address it, consider implementing a mechanism that automatically refreshes the JWT token before it expires. This will prevent session termination after 15 minutes and maintain user authentication without the need for manual page refreshes.
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