feat: logout should navigate by default so middleware can enforce auth on the next render (#956)#960
Merged
Merged
Conversation
…h on the next render (#956) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in, navigation-driven default for NextAuth logout so Next.js middleware re-runs after a user signs out, while preserving existing behavior when not configured.
Changes:
- Added
logoutCallbackUrl?: stringtoNextAuthAuthenticationProviderand threaded it intouseNextAuthService(logoutCallbackUrl). - Introduced
resolveLogoutOptions(options, logoutCallbackUrl)to consistently apply precedence rules and defaultredirectbehavior. - Added unit tests for the pure helper and extended hook tests to cover the new logout option matrix.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/nextauth/types.ts |
Adds logoutCallbackUrl?: string to provider props and documents the behavior. |
src/nextauth/provider.tsx |
Wires the new prop into useNextAuthService(logoutCallbackUrl). |
src/nextauth/hooks/useNextAuthService.ts |
Uses resolveLogoutOptions so requestLogout() can default to redirect when configured. |
src/nextauth/hooks/utils.ts |
New helper that resolves logout options with clear precedence rules. |
tests/resolveLogoutOptions.test.ts |
New unit tests covering helper behavior and precedence. |
tests/useNextAuthService.test.ts |
Extends hook tests to validate logout defaults and overrides. |
5 tasks
…edup test constants (#956) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
NoopDog
approved these changes
Jun 11, 2026
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.
Summary
logoutCallbackUrl?: stringprop onNextAuthAuthenticationProvider, threaded intouseNextAuthService(logoutCallbackUrl).requestLogout()defaults tosignOut({ redirect: true, callbackUrl })so the browser actually navigates and Next middleware re-runs on the next render. Without it, behavior is identical to today (signOut({ redirect: false })).resolveLogoutOptions(options, logoutCallbackUrl)undersrc/nextauth/hooks/utils.ts. Caller-supplied options always win (e.g.requestLogout({ callbackUrl: "/account-disabled", redirect: true })still routes the disabled user correctly; the inactivity-timer's explicit{ callbackUrl, redirect: true }still wins).Closes #956
Back-compat
logoutCallbackUrl:requestLogout()falls through tosignOut({ callbackUrl: undefined, redirect: false })— bit-for-bit identical to current behavior.AuthorizationProviderfor disabled users,useSessionIdleTimerfor inactivity logout): their full options pass through unchanged.AuthenticationConfigshape unchanged — we opted for a provider prop over a config field so the trigger is explicit at the integration site and doesn't require new config plumbing.Test plan
tests/resolveLogoutOptions.test.ts— 6 cases covering the pure helper (no-args defaults, provider-only, caller callbackUrl wins, caller redirect:false wins, full pass-through, caller callbackUrl-only implies redirect:true).tests/useNextAuthService.test.ts— extended with 5 hook-level cases that exercise the new logout matrix.npm run lint,npm run check-format,npx tsc, fullnpm testall clean (469 tests).logoutCallbackUrl, and stale UI no longer lingers.🤖 Generated with Claude Code