Skip to content

feat: oauth autoredirect support - #690

Open
joshtgl wants to merge 4 commits into
oss-apps:mainfrom
joshtgl:feat/oauth-autoredirect
Open

feat: oauth autoredirect support#690
joshtgl wants to merge 4 commits into
oss-apps:mainfrom
joshtgl:feat/oauth-autoredirect

Conversation

@joshtgl

@joshtgl joshtgl commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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:

  • With OAUTH_AUTO_REDIRECT=true and at least one OAuth provider configured, visiting the sign-in page redirects immediately to the first configured OAuth provider.

Checklist

  • I have read CONTRIBUTING.md in its entirety
  • I have performed a self-review of my own code
  • I have added unit tests to cover my changes
  • The last commit successfully passed pre-commit checks
  • Any AI code was thoroughly reviewed by me

Summary by CodeRabbit

  • New Features

    • Added an optional setting to automatically redirect sign-in when exactly one OAuth provider is configured.
    • Automatic redirection remains disabled by default and is skipped while verification or provider loading is active.
    • Sign-in failures during automatic redirection are reported with a notification.
  • Documentation

    • Documented the automatic redirection setting and its configuration requirements.
  • Bug Fixes

    • Added validation and warnings for unsupported automatic redirection configurations.

Comment thread src/env.ts Outdated
Comment thread src/pages/auth/signin.tsx Outdated
Comment thread docs/CONFIGURATION.md Outdated
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c6c0cd6-4b42-412a-af7a-80f8d00f855f

📥 Commits

Reviewing files that changed from the base of the PR and between 7ac60d6 and b8727d5.

📒 Files selected for processing (5)
  • .env.example
  • docs/CONFIGURATION.md
  • src/env.ts
  • src/pages/auth/signin.tsx
  • src/server/auth.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • .env.example
  • src/env.ts
  • src/pages/auth/signin.tsx
  • src/server/auth.ts
  • docs/CONFIGURATION.md

📝 Walkthrough

Walkthrough

Adds the OAUTH_AUTO_REDIRECT setting. The server parses and validates the setting, then passes it to the sign-in page. The page starts OAuth sign-in when exactly one OAuth provider is configured.

Changes

OAuth automatic redirect

Layer / File(s) Summary
Configuration and provider validation
.env.example, docs/CONFIGURATION.md, src/env.ts, src/server/auth.ts
Defines and documents OAUTH_AUTO_REDIRECT, parses it as false by default, and warns when its provider requirements are not met.
Sign-in redirect flow
src/pages/auth/signin.tsx
Passes the setting to the sign-in page and calls signIn when exactly one OAuth provider is available, except when sign-in errors, verification, or provider loading prevent the 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
Loading

Possibly related PRs

  • oss-apps/split-pro#717: Both PRs define boolean environment variables with false defaults and JSON-based runtime parsing.

Suggested reviewers: krokosik

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: support for OAuth automatic redirection.
Description check ✅ Passed The description explains the behavior, includes the demo and checklist sections, and records that unit tests were not added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/env.ts (1)

74-74: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Declare the default in the Zod schema.

OAUTH_AUTO_REDIRECT is optional at Line [74], while the sign-in page requires a boolean. Change the schema to z.boolean().default(false) so validation and the inferred env type 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-nextjs 0.13.8 after this change. As per coding guidelines, src/env.ts must 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

📥 Commits

Reviewing files that changed from the base of the PR and between f0ca6d9 and 60daa81.

📒 Files selected for processing (5)
  • .env.example
  • docs/CONFIGURATION.md
  • src/env.ts
  • src/pages/auth/signin.tsx
  • src/server/auth.ts

Comment thread src/pages/auth/signin.tsx
@joshtgl

joshtgl commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

I verified auto redirect on my local instance when the setting is enabled/disabled.

@joshtgl
joshtgl requested a review from krokosik August 2, 2026 17:02
@krokosik

krokosik commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Great, thank you!

@krokosik

krokosik commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Ready to merge once the conflict is resolved @joshtgl

joshtgl added 4 commits August 3, 2026 14:53
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.
@joshtgl
joshtgl force-pushed the feat/oauth-autoredirect branch from 7ac60d6 to b8727d5 Compare August 3, 2026 18:56
@joshtgl

joshtgl commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

It should be rebased and conflicts resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants