How to handle signing out with AuthSession?

  1. SDK Version: 40
  2. Platforms(Android/iOS/web/all): Android, probably iOS

Hi! I just upgraded from the deprecated authentication method expo-google-app-auth to AuthSession. Overall it’s been a good experience, but I’m hitting an interesting issue - if the user logs out, logging in again doesn’t work until they reload the app. This makes me thing I’m handling signing out incorrectly, but I can’t find mention of how to actually handle that in AuthSession - Expo Documentation or Authentication - Expo Documentation.

What seems to be happening is the useEffect watching response from Google gets fulfilled when the promise is fulfilled, but a new promise isn’t generated until the app reloads. So calling promptAsync works, and the browser opens and redirects as expected, but nothing happens when the user returns to the app - no navigation, no error, no nothing. The useEffect that’s supposed to trigger next steps doesn’t get triggered.

To make this work properly, do I need to find a way to regenerate [request, response, promptLoginAsync], especially response, when the user signs out? Or is there some other function I need to call?

For context, I’m only using Google authentication for the moment, set up following directions at Authentication - Expo Documentation.

Any help is appreciated - happy to provide specific code samples or configurations where useful.

Update: Tried a few things that didn’t work.

Adding Firebase auth signout was helpful, but didn’t fix the issue.

Adding AuthSession.revokeAsync runs without errors, but didn’t fix the issue.

Console logging response shows a successful login result from Google that’s still somehow not triggering that useEffect listening to response.

Next thing I’m trying is putting the login variables (request, response, promptAsync) in state - maybe useEffect will trigger that way? Reading up on useEffect again but really not sure why it’s not getting triggered

It looks like the reason useEffect isn’t triggering is response doesn’t change when the user signs out - it stays as the successful signin response object.

Not sure how the triggering works, because even when I manually assign it to null in the sign out function, useEffect doesn’t seem to see it, at least in time, before it’s reset by Google.useAuthRequest.

Even having useEffect trigger on any update or change (removing the response target) doesn’t get it to listen. I suppose it only checks on re-renders instead of mere changing variables?

Unsure what to try next, or where to look.

It seems that changing state on its own is supposed to work, but it’s not. This code didn’t work:

Nor did these snippets: javascript - React - How to force a function component to render? - Stack Overflow

It only actually re-renders (triggering useEffect) when an actual component changes (e.g. a hidden text component I tested with).

My eventual solution: Instead of bothering with useEffect, I ended up putting duplicate sign-in code into my sign in triggering function. So after await-ing promptLoginAsync, it immediately runs the auth code that was in useEffect.

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