Issue with sesson/cookie on sdk 30

I upgraded from v28 to v30. Now the server thinks the client is not logged in. Server uses session cookies for login. In client side, I use fetch to POST username/password to a login endpoint which sets session cookie. I never needed to pass any extra headers to make it work.

If I revert back to sdk28, the problem goes away. I am using pure Expo, and Android client.

Another user raised the issue here: Issue with Express cookie / session since SDK 29

Hey dude, as you can see from my previous issue that you linked, no one was able to help so I downgraded back to 28. Will give it another shot with 31 but doubtful that it will work either…

After much googling, I have a solution that works for me, so hopefully it will work for others. Basic idea is to

  1. Clear the old stale cookies. The native cookie manager is sending them and causing the server to think that the client is not logged in.
  2. After logging into server, we manually save the data from response.headers[‘set-cookie’] to AsyncStorage (or SecureStore).
  3. When needed, get the cookie from storage and put it in the fetch headers when making a request to the server.

Basic idea for solution came from: Persisting sessions with React Native | by Shrey Gupta | Affinity

However, we cannot use the above solution exactly because react-native-cookies doesn’t work with Expo. Instead, use Networking module:

import { NativeModules } from 'react-native'
const Networking = NativeModules.Networking;
Networking.clearCookies((cleared) => {
    console.debug('cleared hadCookies: ' + cleared.toString());
    ApiUtils.login(your_login_params); // call your login function
});

I was able to log into my server and properly send the session cookie. I tested this on SDK v30 and Android.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.