← Back to Pull requests

fix(mobile): stop the signed-out launch redirect loop #494

Closed
unknown closed this pull request without merging on Oct 31, 2026 04:04 UTC
View on GitHub
unknown unknown commented on Oct 31, 2026 03:41 UTC
Author

What was wrong

After the Expo SDK 58 / expo-router 58.0.26 upgrade (#486), a cold signed-out launch froze on a blank screen and logged "Maximum update depth exceeded" hundreds of times.

Root cause. I instrumented on the iOS simulator (expo-router's guard resolution, Redirect and the navigation tree reducer). The router alternated NAVIGATE_TO_HREF REPLACE /auth → / → /auth:

1. When signed out, the (app) guard fails. It had no redirectTo, so expo-router falls back to the first unguarded sibling in its route sort order. That is auth, because auth is shorter than sign-in (getNavigatorFallback in layouts/GuardContext). The fallback href is /auth.
2. auth.tsx always renders <Redirect href="/" />.
3. / resolves to (app)/(tabs)/index, inside the guarded group, so step 1 runs again.

This is the same mechanism as expo/expo#52072, where the default fallback's URL lands back inside a guarded group. Here the fallback route redirects instead of sharing the URL. It can be fixed in app code, so this needs no patch-package.

Fix

  • apps/mobile/src/app/_layout.tsx: each Stack.Protected now names its target. (app) → /sign-in, and sign-in → /.

  • apps/mobile/src/api/client.ts: on sign-out, the Collection tab refetches after the token is cleared. Those requests go out without a bearer and get 401s. Every 401 used to count as an expired session, so sign-out showed "The API stopped accepting the dev session". Now only a 401 on a request that carried a token expires the session (same change for the export download).

  • apps/mobile/README.md: notes for both changes.
  • Verification

    On an iOS 27 simulator (iPhone 18 Pro, a separate "SW Debug" device) with a native dev build from this branch:

  • Cold signed-out launch (Entra config): the sign-in screen shows after one redirect (/sign-in). No update-depth errors.

  • Dev bypass against a local Functions host:

  • - A cold launch shows sign-in.
    - "Continue as dev user" opens the Collection tab.
    - Profile → Sign out returns to sign-in with no error banner.
    - Signing in a second time and signing out again also works.
    - No JS errors or warnings in the simulator log for the run.
  • npm run typecheck --workspace=apps/mobile, npm run test --workspace=apps/mobile (231 pass) and npm run lint --workspace=apps/mobile all pass.
  • I did not test Entra sign-in itself (it needs real credentials). It goes through the same status → guard path as dev bypass.

    Testing note: the dev build installed on the shared iPhone 18 Pro simulator was built with expo run:ios --port 8082, which compiles the Metro port into the app. It always loads from port 8082, whatever dev-client URL or RCT_jsLocation you set. To test a different worktree you need a separate build (expo run:ios --port <n> --device <other sim>).

    🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Bug Fixes
    Prevented requests sent without an authorization token from triggering session expiration after a 401 response.
    Updated sign-in redirects to prevent loops between signed-in and signed-out routes.
    Prevented token refreshes interrupted by sign-out or a session change from expiring or clearing the replacement session.
    Documentation
    Clarified authentication fallback routing and how 401 responses are handled after sign-out.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 448 lines (+336 / -112) across 5 files Reviewer: mattmck Review duration: 23m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.45) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 448 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.365
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #494"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.4% (MEDIUM) · Higher = larger blast radius
    45.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.6% · Safe to merge
    19.6%