Repository navigation
Redirect users back to original page after sign-in - #167
Conversation
Persist a returnTo URL through all auth flows (OTP, Mastodon OAuth, Misskey MiAuth, HackersPub GraphQL) so users are redirected back to their original page after signing in instead of always landing on /. Includes open-redirect protection via sanitizeReturnTo utility. Fixes #156.
Use beforeLoad with a server function to check auth and redirect immediately, avoiding the React hooks violation from early returns and eliminating any flash of the sign-in page.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (21)
📝 WalkthroughWalkthroughThis pull request implements a redirect-back-to-source feature across the authentication system. A new Changes
Sequence DiagramsequenceDiagram
participant User as User/Client
participant App as App Route
participant SignIn as Auth Sign-in
participant Provider as Auth Provider<br/>(OAuth/MiAuth)
participant SessionStore as Session Store
participant Callback as Callback Handler
User->>App: Request resource (e.g., /events/123)
App->>SignIn: Redirect with returnTo=/events/123
SignIn->>SessionStore: Store returnTo in auth session
SignIn->>Provider: Initiate auth with returnTo param
Provider->>User: Redirect to external auth
User->>Provider: Authenticate
Provider->>Callback: Redirect to callback with auth code
Callback->>SessionStore: Verify auth & retrieve returnTo
SessionStore->>Callback: Return auth data + returnTo
Callback->>User: Redirect to returnTo (validated)
User->>App: Load resource (back at original page)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
returnToredirect flow across all auth providers (OTP, Mastodon OAuth, Misskey MiAuth, HackersPub GraphQL) so users return to their original page after signing in instead of always landing on/returnToin each provider's in-memory session store to persist it across the external OAuth redirect cycle, withsanitizeReturnToutility to prevent open redirect attacksbeforeLoadserver-side auth check to immediately redirect already-signed-in users away from the sign-in page, avoiding React hooks violationsFixes #156
Test plan
returnToparam/auth/signinwhile already logged in — verify immediate redirect to//auth/signin?returnTo=/settingswhile already logged in — verify immediate redirect to/settings/settings,/calendar,/groups/create,/events/createwhile logged out — verifyreturnTois passed and works after sign-inSummary by CodeRabbit