Expo Supabase OAuth Callback Not Reopening App
In this article
Expo Supabase OAuth callbacks fail to reopen your app because the redirect URL that Supabase sends the browser to is not registered in your app's scheme or universal link configuration, or because the OAuth flow is running in a browser context that cannot hand control back to the native app. The fix is to make the redirect URL match exactly what your Expo app is configured to handle, then ensure the browser session is opened in a way that allows the callback to return to the app.
What You'll Need
- An Expo project using Supabase authentication (expo-auth-session, expo-web-browser, or supabase-js with a custom storage adapter).
- Access to your Supabase project dashboard (Authentication > URL Configuration).
- Your app's scheme configured in app.json or app.config.js (for example,
myapp). - A development build or a production build installed on a device or simulator. Expo Go has limitations with custom schemes and deep links, so a development build is strongly recommended for testing OAuth redirects.
Step-by-Step
- Confirm your app scheme is set. Open app.json (or app.config.js) and check the
expo.schemefield. It should be a unique string likemyapp. If it is missing, add it. Then rebuild the app (a new development build or production build) because scheme changes do not apply to an already-installed binary. - Choose a redirect URL that matches your scheme. The simplest reliable pattern is
myapp://auth/callbackormyapp://. Avoid usingexp://URLs for production; those are for Expo Go and often fail to reopen the app after the OAuth provider redirects. If you use a universal link (https), you must also configure associated domains (iOS) and intent filters (Android); for most Expo apps the custom scheme is easier. - Add the redirect URL to Supabase. In the Supabase dashboard, go to Authentication > URL Configuration. Under Redirect URLs, add the exact URL you will pass as
redirectTo(for example,myapp://auth/callback). Wildcards are allowed but be precise; a missing trailing slash or a different path will cause the callback to be rejected or to land on a blank page. Also set the Site URL to a valid fallback, though for native apps the redirect URL list is what matters. - Pass the same redirectTo in your sign-in call. When you call
supabase.auth.signInWithOAuth({ provider: 'google', options: { redirectTo: 'myapp://auth/callback' } }), the value must exactly match one of the URLs in Supabase. If you use expo-auth-session, you can build the redirect URI withAuthSession.makeRedirectUri({ scheme: 'myapp', path: 'auth/callback' })and pass that to Supabase. Do not hardcode different strings in different places. - Open the OAuth flow in a browser that can return to the app. Use
WebBrowser.openAuthSessionAsync(url, redirectUrl)from expo-web-browser, or the equivalent method in your auth library. A plainLinking.openURLor opening the URL in an in-app webview will not reliably close and return to your app. The auth session API is designed to capture the redirect and dismiss the browser automatically. - Handle the callback URL in your app. After the browser closes, parse the returned URL for the
codeoraccess_tokenparameter and exchange it for a session usingsupabase.auth.exchangeCodeForSession(code)(for PKCE flow) or by setting the session from the fragment (implicit flow). Make sure your app's deep link handler (via expo-linking or React Navigation linking config) routes the callback path to the screen that performs this exchange. - Test on a real device with a development build. Install the development build, run the sign-in, and watch whether the browser closes and the app comes to the foreground. If it does not, check the device logs for the received URL. On iOS, also verify that the scheme is listed in Info.plist (Expo generates this from app.json). On Android, check the intent filter in AndroidManifest.xml (also generated). Rebuild after any config change.
Common Mistakes
- Using
exp://redirect URLs in a standalone or development build. These only work in Expo Go and often fail to reopen the app. - Mismatched redirect URLs: a trailing slash, http vs https, or a different path between the Supabase dashboard and the app code.
- Forgetting to rebuild after changing the scheme or adding a new intent filter. The installed binary keeps the old configuration.
- Opening the OAuth URL with
Linking.openURLinstead of an auth session, so the browser has no mechanism to return to the app. - Not handling the deep link in the app, so the app opens but shows the home screen instead of completing the session exchange.
- Using the implicit flow without configuring the redirect to include the access token in the fragment, or using PKCE without exchanging the code.
Tips
- Keep a single source of truth for the redirect URL in your code and reuse it in Supabase settings.
- Use a development build from the start when testing OAuth; it behaves like a production app for deep links.
- Log the URL returned by the auth session to see exactly what the provider sent back.
- If you must use a universal link, test both the app-installed and app-not-installed cases; the fallback should be a web page that instructs the user.
- Check Supabase logs (Authentication > Logs) for redirect URL mismatch errors.
Troubleshooting
If the browser opens but never returns to the app, first confirm the redirect URL in Supabase matches the one in your code exactly. Then verify the app was rebuilt after any scheme change. On iOS, ensure the scheme is in Info.plist; on Android, check the intent filter. If the app opens but no session is created, inspect the callback URL for a code parameter and make sure your deep link handler routes it to the exchange function. If you see an error page from Supabase, the redirect URL is likely not in the allowed list. As a last resort, try a minimal test with a known-good scheme like myapp:// to isolate the issue.
Frequently Asked Questions
Why does the browser stay open after sign-in?
Because the redirect URL is not registered with the app's scheme, or the browser session was not opened with an auth session API that can dismiss itself. Check both.
Can I use exp:// URLs in production?
No. exp:// is for Expo Go only. Use a custom scheme or universal link for development and production builds.
Do I need to rebuild after changing the scheme?
Yes. The scheme is compiled into the native binary, so a new build is required.
What if the app opens but shows the wrong screen?
Your deep link handler is not routing the callback path to the screen that exchanges the code for a session. Configure your navigation linking.
Why does Supabase reject my redirect URL?
The URL is not in the allowed Redirect URLs list, or it does not match exactly (including trailing slash). Add the exact URL in the dashboard.
Does this work in Expo Go?
Partially, but custom schemes are limited. For reliable OAuth callbacks, use a development build.