Skip to content
Back

Expo-web session issue

  • 0
  • React Native
  • Web
  • Auth
  • Cloud
Axistro
18 Jul, 2025, 18:28

In web

I created a session using oauth. I run the app logged in but closed the terminal and ran again opened the app(I have now 2 running app in different tab) session is ok close every tab and terminal re run the app there is no session. Either expo clearing the cookies set by appwrite or something else is happening . check is this is the reason

TypeScript
  if (Platform.OS === 'web') {
    // Web: get params from window.location
    const params = new URLSearchParams(window.location.search);
    const secret = params.get('secret');
    const userId = params.get('userId');

    if (secret && userId) {
      try {
        const res = await account.createSession(userId, secret);
        console.log(res);
        window.history.replaceState({}, document.title, window.location.pathname);
        
        return await getAccount();
      } catch (e) {
        console.error('Failed to create session:', e);
        return null;
      }
    }
    return null;
  }

this is my code. why am I using url search on window?

TypeScript
const result = await WebBrowser.openAuthSessionAsync(loginUrl, scheme);

this is opening a another window (smaller) and redirects in that window. My app is not able to catch that params, which is in the new window. so I set the redirect url as a screen for web and instead of opening new window i dont do anything and on redirect the screen catches the url and creates session. but after that the thing happens what i said at the start. Stuck on development. (Works on expo go)

TL;DR
Developers experiencing an issue with session persistence in Expo-web. The code snippet provided appears to clear cookies or face difficulties in maintaining session after re-running the app. This could be due to redirects in a new window causing session loss. The suggested solution is to modify the redirect URL and avoid opening new windows for authentication. The issue persists even after these changes. The problem is prominent during development but works in Expo Go.
Axistro
18 Jul, 2025, 18:34

Any thing I am doing wrong? I thought it was some kind of dev mode issue so i hosted it same thing happens

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