'Expo AuthSession new window not redirecting on Web
We are using AuthSession.startAsync to initiate an authentication process in our app, which is working fine on iOS and Android. However when we run it the web browser, instead of redirecting to the correct Auth0 sign in page, our sign in process is just opening another window of the app.
Code that’s causing the problem:
const result = await AuthSession.startAsync({
authUrl,
returnUrl: Platform.OS === 'web' ? getRedirectUri() : undefined,
});
Right now the authUrl is the correct url we need going to auth0, however it doesn’t open this url the way it does on mobile for signing in. Has anyone ran into this AuthSession issue before on an Expo web app?
Thanks in advance!
Solution 1:[1]
You need to call WebBrowser.maybeCompleteAuthSession();
.
There is a warning in the AuthSession Expo Docs about this case:
? In order to close the popup window on web, you
need to invoke WebBrowser.maybeCompleteAuthSession().
See the Identity example for more info.
The example they are talking about can be found here:
https://docs.expo.dev/guides/authentication/#identityserver-4
Solution 2:[2]
Just add WebBrowser.maybeCompleteAuthSession();
under imports in your login component file. Opened window will resolve correctly in Web.
It is not needed in android or ios app.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | kidcapital |
Solution 2 | Orawko |