feat: oauth autoredirect support - #690
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughAdds the ChangesOAuth automatic redirect
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Environment
participant getServerSideProps
participant Home
participant OAuthProvider
Environment->>getServerSideProps: Read env.OAUTH_AUTO_REDIRECT
getServerSideProps->>Home: Pass oauthAutoRedirect
Home->>OAuthProvider: Call signIn(provider.id) when one OAuth provider is available
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/env.ts (1)
74-74: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDeclare the default in the Zod schema.
OAUTH_AUTO_REDIRECTis optional at Line [74], while the sign-in page requires a boolean. Change the schema toz.boolean().default(false)so validation and the inferredenvtype use the same contract.Proposed fix
- OAUTH_AUTO_REDIRECT: z.boolean().optional(), + OAUTH_AUTO_REDIRECT: z.boolean().default(false),Verify the inferred type with
@t3-oss/env-nextjs0.13.8 after this change. As per coding guidelines,src/env.tsmust define fallback defaults with Zod.default().🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/env.ts` at line 74, Update the OAUTH_AUTO_REDIRECT schema entry in the env validation definition to use z.boolean().default(false) instead of optional(), so validation and the inferred env type always provide a boolean while following the project’s Zod default convention.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/pages/auth/signin.tsx`:
- Around line 114-124: Update the automatic redirect logic in the sign-in
useEffect by requiring !error in shouldAutoRedirect, and include error in the
effect dependency list so callback failures do not restart OAuth.
- Around line 114-124: Update the automatic sign-in flow in the useEffect
callback to catch rejected signIn promises and display
toast.error(t('errors.signin_error')). Include t in the effect dependency array
while preserving the existing redirect conditions.
---
Nitpick comments:
In `@src/env.ts`:
- Line 74: Update the OAUTH_AUTO_REDIRECT schema entry in the env validation
definition to use z.boolean().default(false) instead of optional(), so
validation and the inferred env type always provide a boolean while following
the project’s Zod default convention.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 63c833ed-6fb3-4619-929e-1c4c71d5424d
📒 Files selected for processing (5)
.env.exampledocs/CONFIGURATION.mdsrc/env.tssrc/pages/auth/signin.tsxsrc/server/auth.ts
|
I verified auto redirect on my local instance when the setting is enabled/disabled. |
|
Great, thank you! |
|
Ready to merge once the conflict is resolved @joshtgl |
Only auto-redirect when exactly one OAuth provider is configured and no other authentication providers are enabled. Warn at startup for invalid configurations and document the required environment setup.
Skip automatic OAuth redirection when a sign-in error is present, preventing failed callbacks from restarting the OAuth flow. Show an error toast when the automatic sign-in promise rejects and include the translation function in the effect dependencies.
Ensure OAUTH_AUTO_REDIRECT always resolves to a boolean during environment validation.
7ac60d6 to
b8727d5
Compare
|
It should be rebased and conflicts resolved. |
Description
Adds optional automatic redirect from the sign-in page to the first configured OAuth provider when
OAUTH_AUTO_REDIRECT=true.Let me know if any other changes/updates are needed.
Demo
No UI screenshots included. Behavior change is:
OAUTH_AUTO_REDIRECT=trueand at least one OAuth provider configured, visiting the sign-in page redirects immediately to the first configured OAuth provider.Checklist
CONTRIBUTING.mdin its entiretySummary by CodeRabbit
New Features
Documentation
Bug Fixes