Skip to main content

Supabase Magic Links, Password Reset and Email Confirmation in Expo: Making Email Links Open Your App

Updated 8 min readMarkdown

Why Supabase auth emails open a browser (or a blank screen) instead of your Expo app, and how to fix magic links, password reset and sign-up confirmation with deep links, PKCE and one-time codes.

Supabase auth emails contain links that redirect to a URL you choose. In an Expo app, that URL must be a deep link your app handles (like myapp://auth/callback), it must be on Supabase's list of allowed redirect URLs, and your app must exchange the code in that link for a session. With the PKCE flow, the link must also open on the same device and app that requested it. If deep links keep breaking, switch magic links to 6-digit email codes, which avoid links entirely and work in every email client.

Email auth works perfectly in a browser. Then you move to an Expo app, tap the magic link in your inbox, and you land on your website's homepage, a blank browser tab or a "localhost refused to connect" error. Password reset and sign-up confirmation break in the same way.

The cause is always one of four things: the redirect URL, the allow list, the flow type or the handler in your app. This guide fixes each one.

Every Supabase auth email (magic link, confirmation, password reset) contains a link to Supabase's servers. Supabase verifies it and then redirects to a URL. If you don't specify one, it redirects to your project's Site URL, usually your website or localhost:3000.

To land in your app, three things must line up:

  1. Your app passes a redirect URL that opens the app, such as myapp://auth/callback.
  2. That URL is on Supabase's allow list. If it isn't, Supabase ignores it and falls back to the Site URL.
  3. Your app handles the incoming link and turns it into a session.

Step 1: Give your app a URL scheme

In app.json:

{
  "expo": {
    "scheme": "myapp"
  }
}

Rebuild your development build after changing it. Then build redirect URLs with expo-linking, which produces the right format for each environment (your custom scheme in builds, an exp:// URL in Expo Go):

import * as Linking from 'expo-linking';

export const authCallbackUrl = Linking.createURL('/auth/callback');
// e.g. myapp://auth/callback in a development or store build

Step 2: Add your redirect URLs in Supabase

In the Supabase dashboard, go to Authentication → URL Configuration and add your app's URLs to Redirect URLs:

  • myapp://** for your builds (Supabase supports wildcard patterns; check the docs for the current syntax)
  • Your Expo Go development URL if you test there (the exp:// URL createURL prints)

Keep the Site URL set to your website. It's the fallback for anything not on the list.

If your link lands on the Site URL instead of your app, this step is almost always the reason.

Step 3: Use the PKCE flow in your client

Configure the Supabase client for mobile with PKCE:

import 'react-native-url-polyfill/auto';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { createClient } from '@supabase/supabase-js';

export const supabase = createClient(
  process.env.EXPO_PUBLIC_SUPABASE_URL!,
  process.env.EXPO_PUBLIC_SUPABASE_ANON_KEY!,
  {
    auth: {
      storage: AsyncStorage,
      autoRefreshToken: true,
      persistSession: true,
      detectSessionInUrl: false,
      flowType: 'pkce',
    },
  }
);

With PKCE, the redirect contains a short-lived code in the query string (?code=...) instead of tokens in the URL. Your app exchanges the code for a session.

The PKCE gotcha: when your app starts the flow, the client stores a secret "code verifier" on the device. The exchange only works on the same device and app that requested the email. A magic link opened on a laptop, or in a different app install, can't complete. That's by design, and it's the most common "it works for me but not for users" bug.

Step 4: Handle the callback in your app

With Expo Router, create a route that matches the redirect path. The code arrives as a search param:

// app/auth/callback.tsx
import { useEffect } from 'react';
import { ActivityIndicator, View } from 'react-native';
import { router, useLocalSearchParams } from 'expo-router';
import { supabase } from '@/lib/supabase';

export default function AuthCallback() {
  const { code, type } = useLocalSearchParams<{ code?: string; type?: string }>();

  useEffect(() => {
    async function finish() {
      if (!code) {
        router.replace('/sign-in');
        return;
      }
      const { error } = await supabase.auth.exchangeCodeForSession(code);
      if (error) {
        router.replace('/sign-in?error=link-expired');
        return;
      }
      // Password reset links continue to the "choose a new password" screen
      router.replace(type === 'recovery' ? '/reset-password' : '/');
    }
    finish();
  }, [code, type]);

  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <ActivityIndicator />
    </View>
  );
}

Use router.replace so the callback screen isn't left in the back stack.

import { supabase } from '@/lib/supabase';
import { authCallbackUrl } from '@/lib/links';

export async function sendMagicLink(email: string) {
  const { error } = await supabase.auth.signInWithOtp({
    email,
    options: { emailRedirectTo: authCallbackUrl },
  });
  if (error) throw error;
}

Show a clear "Check your email" screen afterwards, and tell users to open the link on this phone.

How do I handle password reset in Expo with Supabase?

Password reset is two parts: send the email, then let the user set a new password once they're back in the app.

export async function sendPasswordReset(email: string) {
  const { error } = await supabase.auth.resetPasswordForEmail(email, {
    redirectTo: `${authCallbackUrl}?type=recovery`,
  });
  if (error) throw error;
}

When the link opens the app, the callback exchanges the code (which signs the user in) and routes to /reset-password, where you update the password:

const { error } = await supabase.auth.updateUser({ password: newPassword });

Then send them into the app. Ask for the new password twice, and show requirements up front.

How do I make sign-up confirmation emails open my app?

Pass the same redirect when signing up:

const { error } = await supabase.auth.signUp({
  email,
  password,
  options: { emailRedirectTo: authCallbackUrl },
});

When the user taps "Confirm your email", Supabase verifies it and redirects to your callback, which completes sign-in. Until then, show a "Confirm your email" screen with a "Resend email" button.

The more reliable option: 6-digit email codes

Deep links from email depend on things you don't control: which email app the user has, whether it opens links in an in-app browser and whether they read email on another device. For mobile apps, one-time codes remove all of that.

  1. Edit the email template in Supabase (Authentication → Emails) to show the code. Supabase's templates expose the code as {{ .Token }}, so the email can say "Your sign-in code is {{ .Token }}" instead of (or alongside) the link.
  2. Send the email with signInWithOtp, exactly as before.
  3. Verify the code in the app:
export async function verifyEmailCode(email: string, token: string) {
  const { error } = await supabase.auth.verifyOtp({ email, token, type: 'email' });
  if (error) throw error;
}

Users copy a short code from any device, the app never leaves the screen, and the whole deep link problem disappears. On iOS, set textContentType="oneTimeCode" on the input so the keyboard can suggest it.

Why do Supabase emails stop arriving in production?

Supabase's built-in email service is meant for development and has strict sending limits. For production, configure custom SMTP (Authentication settings) with a transactional email provider, and set up your domain's SPF and DKIM records so emails don't land in spam. Many "magic links don't work" reports are actually "emails never arrived".

Troubleshooting checklist

  • Lands on the website or localhost: the redirect URL isn't on the allow list, so Supabase used the Site URL.
  • Opens the browser, then nothing: the scheme isn't registered in the build you're running; rebuild after setting scheme.
  • "Invalid flow state" or code exchange fails: the link was opened on a different device or app install than the one that requested it (PKCE), or it expired. Request a new one.
  • Works in Expo Go, not in the store build (or the reverse): the exp:// and myapp:// URLs differ; add both to the allow list.
  • Link opens inside the email app's browser: some email apps do this. Use universal links or app links with your own domain, or switch to email codes.
  • Emails don't arrive: set up custom SMTP and check spam.

Conclusion

Supabase email auth in Expo works reliably once four pieces line up: a URL scheme, an allow-listed redirect, the PKCE code exchange in a callback route, and awareness that the link must open on the same device. For the smoothest mobile experience, consider 6-digit email codes, which skip deep links entirely.

Magic links or email codes: which do you use in your Expo app, and why? Share your setup in the comments.

No comments yet. Be the first to comment.