WebBrowser.openAuthSessionAsync(url, callbackUrl) function can't go back to original page and cannot get the data when successfully loggedin

500 views Asked by At

I am using expo-web-browser to open my login page in a web using open openAuthSessionAsync but I cannot get the data or I cannot return to my app after it successfully logged in with this code.

import * as Linking from 'expo-linking';
import * as WebBrowser from "expo-web-browser";

const [result, setResult] =
React.useState<WebBrowser.WebBrowserAuthSessionResult | null>(null)

React.useEffect(() => {
  console.log("result",result)
}, [result])

this is the action button

 signIn = () => {    
     const callbackUrl = Linking.makeUrl();
     WebBrowser.openAuthSessionAsync('https://..../login', callbackUrl)
 }
1

There are 1 answers

0
RilDev On

Linking.makeUrl() is deprecated.

I am using Supabase, feel free to use whatever you prefer.

Here is the code:

const redirectURL = Linking.createURL("/auth");

const result = await WebBrowser.openAuthSessionAsync(
  `${
    process.env.EXPO_PUBLIC_SUPABASE_URL
  }/auth/v1/authorize?${new URLSearchParams({
    provider: "google",
    redirect_to: redirectURL,
  })}`,
  redirectURL
);

Note: If you are using Supabase, don't forget to add "Redirect URLs". In this case, you could add expo://** and myapp://** where you'd replace myapp by the value set in expo.scheme in your app.json file.