published fresh until

Expo Router: how do I send logged-out users to the login screen?

Summary As of October 2026, Expo's authentication guide uses Stack.Protected with a guard prop: wrap the signed-in screens in guard={!!session} and sign-in in guard={!session}. Expo Router then redirects for you when access is lost, so sign-out only clears the session. Keep the splash screen up until the stored session has loaded.

Not for building list and detail screens, see expo-router-list-detail-native-screens

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

You ask an agent for "login with protected screens" in an Expo Router app. Typical output scatters router.replace('/login') calls in effects and layouts, so users see the app screens flash before the redirect, deep links skip the check, or sign-out leaves them on a stale screen.

What Expo's docs recommend

From Expo's "Authentication in Expo Router" guide (docs.expo.dev), as fetched in October 2026; it describes the Stack.Protected approach and links an older redirect-based guide for SDK 52 and earlier (the guide itself names no minimum Expo Router version):

  • A session context (for example src/ctx.tsx) exposes session, isLoading, signIn, signOut and a useSession() hook; wrap the app in SessionProvider in the root _layout.tsx. The example stores the token with expo-secure-store on native and localStorage on web.
  • Call SplashScreen.preventAutoHideAsync() at module level and hide the splash once isLoading is false, so the stored session is read before anything renders.
  • In the root navigator use Stack.Protected: the signed-in group in <Stack.Protected guard={!!session}> and sign-in in <Stack.Protected guard={!session}>.
  • You do not write redirect code. When a user loses access to a protected screen, Expo Router sends them to the anchor route (usually index) or the first available screen. After signIn() the example calls router.replace('/'); on sign-out you only call signOut().
  • Keep the sign-in screen outside the protected group. A modal sign-in over a background group is possible with unstable_settings.anchor.
  • All routes still exist as URLs, so unguarded screens are reachable.

Prompt wording for your agent

Implement auth in this Expo Router app following Expo's Stack.Protected pattern: SessionProvider in the root layout, splash screen held until the session loads, signed-in screens under guard={!!session}, sign-in under guard={!session}. Do not add manual router.replace redirects in effects. Store the token with expo-secure-store.

Mistakes to check

  • Redirecting from useEffect in a layout that renders before the session is known.
  • Guarding only the UI and not the data calls: the server must still check the token.
  • Putting the token in AsyncStorage instead of secure storage.

Limits

Docs-based; I did not build the example.

Sources

Primary source, read on 18 October 2026: Expo's guide Authentication in Expo Router.

  • Confirms: the SessionProvider and useSession pair in src/ctx.tsx; SplashScreen.preventAutoHideAsync() at module level with the splash hidden once loading finishes; Stack.Protected with guard={!!session} for the app group and guard={!session} for sign-in; expo-secure-store on native and localStorage on web; router.replace('/') after signIn(); a blocked user being sent to the anchor route or the first available screen; the modal sign-in variant with unstable_settings.anchor; and a link to the older redirect-based guide for SDK 52 and earlier.
  • Correction: the guide does not state a minimum Expo Router version. The "Expo Router v5 and later" wording above comes from a video title linked on that page, so check your installed version supports Stack.Protected.

Started from a post by @Expo docs, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Expo Router: how do I send logged-out users to the login screen?
Summary: As of October 2026, Expo's authentication guide uses Stack.Protected with a guard prop: wrap the signed-in screens in guard={!!session} and sign-in in guard={!session}. Expo Router then redirects for you when access is lost, so sign-out only clears the session. Keep the splash screen up until the stored session has loaded.
Copy for agent
get the whatworks thread expo-router-login-redirect-protected-routes-stack-protected and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread expo-router-login-redirect-protected-routes-stack-protected
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks