Skip to main content
For an in-depth guide to deeplinking with Expo, refer to the Expo docs.Below is a summary of the steps required:
1

Declare your app scheme in app.json

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

Create the base URL

Use Linking.createUrl() from the expo-linking package to create the base URL you will pass into the login_magic_link_url and signup_magic_link_url params for calls to initiate magic links. Linking.createUrl() will return exp://127.0.0.1:19000 for Expo apps in development, exp://exp.host/@community/with-webbrowser-redirect for apps published in Expo Go, and myapp:// for published apps. This way, you can pass the value returned by Linking.createUrl() into stytchClient.magiclinks.email.loginOrCreate and it will work for both development and production cases. Your initiate call will look something like this:
const baseUrl = Linking.createUrl();
const magicLinkBaseUrl = baseUrl + '/authenticate';
stytchClient.magicLinks.email.loginOrCreate('email', {
  login_magic_link_url: magicLinkBaseUrl,
  login_expiration_minutes: 60,
  signup_magic_link_url: magicLinkBaseUrl,
  signup_expiration_minutes: 60,
});
3

Handle the deep link

In the above use case, when a user clicks the magic link in their email, they will be redirected to the route you passed in, with a token attached as a query parameter. You will then use the token from the query param to authenticate your user with stytchClient.magicLinks.authenticate(token, {session_duration_minutes: 60}); For detailed information on handling deep links into your Expo app, check out the Expo docs here. An example using react-navigation could look like this:
type RootStackParamList = {
  Home: undefined,
  Authenticate: { token: string }
}
type AuthenticateScreenProps = NativeStackScreenProps<RootStackParamList, 'Authenticate'>;
const AuthenticateScreen: React.FC = ({ route }: AuthenticateScreenProps) => {
  React.useEffect(() => {
      stytch.magicLinks.authenticate(
        route.params.token,
        { session_duration_minutes: 60 })
        .then((res) => {
          // do something with user/session data
        })
        .catch((e) => {
          // handle error
        })
    }
  }, []);
}