Skip to content
Back

Unable to Delete Session Before Logging in Again (Google OAuth2 Issue)

  • 0
  • Flutter
  • Auth
  • Cloud
marcosasu
1 Jan, 2025, 18:08

Hi everyone,

I'm facing an issue with session management in Appwrite when using Google OAuth2 for authentication. Here's the problem:

When a user logs in via Google OAuth2, the session gets saved in the browser cookies. If the app is reinstalled, the session persists in the browser, and the user cannot re-login properly without first deleting the existing session. Calling deleteSession("current") requires the user to already be authenticated, which is not possible in this scenario because the user is no longer technically logged in due to the app being reinstalled. This creates a loop where:

I can't delete the session because the user isn't logged in. I can't log in again because the previous session is still active in the cookies. The user also cannot log in using a different Google account because the previous session prevents any new login attempts. I've tried using setSession("current") before calling deleteSession, but I still encounter the error: User (role: guests) missing scope (account).

Is there a way to delete the session without requiring the user to be logged in? Or is there a workaround to manage this properly?

Thanks in advance for any help or insights!

TL;DR
Issue: Unable to delete session before new login due to Google OAuth2 session persistence causing authentication loop. Solution: Implement a workaround by resetting the session state before trying to delete the session. This can be achieved by clearing browser cookies or utilizing a temporary session state for managing logins.
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