Repository navigation
feat(auth): protect deeplinked screens and return to them after login - #183
Draft
fernandatoledo wants to merge 6 commits into
Draft
fernandatoledo wants to merge 6 commits into
fernandatoledo wants to merge 6 commits into
Conversation
💯 Test Coverage
😎 Tests Results
👀 Tests Details • (74%)
|
… routes - Guards always send an authenticated user to `/`. PendingDeepLinkHandler then pushes the pending link on top of `(app)`, so the linked screen keeps a back stack. - isReturnToPath matches an allow-list of protected routes, so unknown routes open the 404 instead of asking for sign-in. A test fails when a route is not classified. - AuthProvider re-checks the stored token on foreground and when +native-intent finds it expired, so the guards and +native-intent agree on the session. - runtimeVersion uses the fingerprint policy, so updates only reach builds that register the same scheme.
- Drop the AppState re-check: logging a user out on foreground with no notice is a product decision. Links still sync the session through syncSession(). - Restore the appVersion runtime policy. expo-updates is not installed, and the fingerprint hashes extra, which can strand OTAs built from a different env file. - Make the unmount test fail when the session listener is not removed.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira board reference:
What does this do?
Deep links into protected screens now send a logged-out user to sign-in, show "Sign in to open this link.", and take them to the linked screen after they log in instead of
/, opened on top of the tabs so back returns to the app.feed/[id]andfeed/add-postmove under the authenticatedStack.Protectedguard (they were reachable without a session), and the guarded screen lists now live insrc/lib/auth/deep-link-path.tsand are rendered from there. The app scheme is also suffixed per environment (RootstrapApp.development,.qa,.staging; production staysRootstrapApp) so several builds can be installed side by side.Why did you do this?
Opening a link to a protected screen while logged out lost the target: after login the user always landed on
/. Using the same scheme for every environment meant a link could open the wrong installed build.Who/what does this impact?
src/app/+native-intent.tsxrecords the link in an in-memory store (src/lib/auth/pending-deep-link.ts) and, when there is no valid session, sends the user straight to the guard's fallback (/sign-in, or/onboardingon first launch) so the protected screen is never pushed. The session check is shared withAuthProviderthroughhasValidSession(), and when a link finds the stored token expired,syncSession()makes a runningAuthProviderdrop it too, so the guards and+native-intentagree. Only links that resolve to a protected route are remembered:isReturnToPath()matches an allow-list built fromAUTHENTICATED_SCREENSandAPP_TAB_SCREENS, so public, auth and unknown routes open unchanged. A test walkssrc/appand fails when a route file is not classified. The link is dropped on onboarding, when the logged-out user leaves the auth screens, and when a newer link arrives.src/app/_layout.tsx: the guards always send an authenticated user to/, andPendingDeepLinkHandlerthen pushes the pending link once the tabs are showing and the session is valid, so the linked screen keeps a back stack (header back, swipe-back, Android back). Also the sign-in screen (LoginFormgets an optionalnotice). While auth is hydrating the root layout now renders nothing and keeps the splash, instead of an unguarded<Stack />; the splash is hidden there once auth is ready (it used to be hidden from(app)/_layout.tsx, which never mounts in that window anymore).guides/navigation.mdx,agent_docs/architecture.mdandREVIEW.md.Layer 2: Risk Classification
Author applies a risk label when opening the PR. When in doubt, escalate.
risk:lowrisk:mediumrisk:highSetup
risk:low,risk:medium,risk:highlabels in the repoHow did you test this?
pnpm check-allpasses (lint, type-check, translations, 45 suites / 404 tests).APP_ENV=<env> npx expo config --type publicshows the expected scheme for each environment. On the iOS Simulator with a development build (old schemeRootstrapApp) and Maestro:feed/1andfeed/add-postland on sign-in with the message, both on cold start and with the app running;The redirect to the link after login was checked on the simulator against a local mock of the sign-in endpoint (the development backend didn't accept the test login):
logged out, a link to
feed/add-post→ sign-in → login → Add Post with a "Feed" back button, and back returns to the tabs; same forfeed/1→ Post;logged in with a 60-second token left to expire with the app in the foreground, a link to
feed/add-postgoes to sign-in with the message instead of opening the screen with a dead token.Tested on iOS
Tested on Android
Tested on a small device
Tested on a real device
Tested all flows related with this PR changes
Tested accessibility
Added tests
Notes:
+native-intentonly runs on native, so on web a logged-out user is still sent to sign-in but the link is not restored.expo-router/testing-library'srenderRoutercan't run in this repo (transitivereact-test-renderer19.1 vs React 19.3), so the guard tests mockStack.Protected. A follow-up could alignreact-test-rendererand add an end-to-end router test for the post-login redirect.Screenshots / Previews
🧑🎨 Figma Design:
📱 Android:
📱 iOS:
Logged out: cold start from a link to
feed/1lands on sign-in with the message, a link tosign-upopens normally, a link tosign-inshows no message, and a link tofeed/add-postgoes straight to sign-in without rendering the protected screen.deeplink-protected-screens-v2.mp4
Return to the link after login: logged out, a link to
feed/add-postopens sign-in with the message, and after signing in the app lands on Add Post. Recorded against a local mock of the sign-in endpoint.deeplink-login-return-to.mp4