fix: harden Next.js AuthKit skill against Server Component cookie violations#13
Merged
fix: harden Next.js AuthKit skill against Server Component cookie violations#13
Conversation
…lations
- Rewrite Step 8 UI Integration with explicit NavAuth client component
pattern using useAuth() + refreshAuth({ ensureSignedIn: true })
- Add useAuth import from @workos-inc/authkit-nextjs/components
- Warn against raw getAuthorizationUrl() usage (returns object, not string)
- Add error recovery sections for [object Object] and OAuth state mismatch
- Add verification checks for unsafe auth URL patterns
- Add anti-pattern checks to authkit-nextjs-protected eval case
- Add authkit-nextjs-nav-auth-pkce regression eval case
- Add scorer regression test (broken: 59, fixed: 98)
Addresses Alexander Southgate's friction log: getSignInUrl() in Server
Components, [object Object] redirect, and PKCE state mismatch.
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
When running
workos installon a Next.js B2B app, the installer agent could generate auth UI with three failure modes:nav-auth.tsxas a Server Component callinggetSignInUrl(), which sets PKCE cookies. Next.js 16 forbids cookie modification during render.[object Object]redirect — SDK'sactions.jscallsgetAuthorizationUrl()which returns{ url, sealedState }, not a string.sealedStatediscarded when using rawgetAuthorizationUrl(), so PKCE cookie never set.Bugs 2-3 are SDK bugs (out of scope here). Bug 1 is fixed by strengthening the skill reference that guides the installer agent.
Changes
Reference guide (
workos-authkit-nextjs.md)Step 8 rewrite — the old Step 8 ended with "See README for the recommended approach", which was too vague for the agent to follow reliably. The new version:
NavAuthclient component example usinguseAuth()+refreshAuth({ ensureSignedIn: true })with the correct import from@workos-inc/authkit-nextjs/componentsgetAuthorizationUrl()(returns object, not string; drops PKCE cookie)rgfor unsafe patterns in generated code[object Object]redirect and OAuth state mismatchEval cases (
authkit-nextjs.yaml)authkit-nextjs-protected— removedgetSignInUrlfrom expected methods (it shouldn't appear in server component answers) and added it as an anti-pattern for server component usage. Addedform action={await getSignInUrl()}anti-pattern.authkit-nextjs-nav-auth-pkce(new) — regression case that directly encodes the three-bug scenario. Tests forAuthKitProvider,useAuth,refreshAuth,ensureSignedIn, and penalizesgetSignInUrlin server components, rawgetAuthorizationUrl,window.location.href = auth.signInUrl, and discardedsealedState.Scorer regression test (
eval-scorer.spec.ts)Compares a broken implementation (the exact bug pattern) against the fixed implementation. Broken scores ≤60, fixed scores ≥80, and the broken pattern triggers
security_issueerror category.Eval results
authkit-nextjs-nav-auth-pkceauthkit-nextjs-protectedCompanion PR: workos/cli#110 (NextjsGrader structural check)