Skip to content

Commit 7b53d20

Browse files
Fix PKCE code verifier authentication error
Add explicit cookie configuration for PKCE code verifier to resolve 'InvalidCheck: pkceCodeVerifier value could not be parsed' error. This fixes an issue where OAuth authentication would fail on first attempt due to NextAuth v5 not having explicit cookie settings for PKCE flow. The explicit configuration ensures cookies are properly stored and retrieved during the OAuth callback, preventing authentication failures. - Add pkceCodeVerifier cookie configuration with proper security settings - Use dynamic secure flag based on AUTH_URL protocol (HTTP vs HTTPS) - Set appropriate cookie options (httpOnly, sameSite, path, maxAge) - Handle undefined AUTH_URL during build time with optional chaining Co-authored-by: Brendan Kellam <brendan@sourcebot.dev>
1 parent fb358d8 commit 7b53d20

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

packages/web/src/auth.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
158158
strategy: "jwt",
159159
},
160160
trustHost: true,
161+
cookies: {
162+
pkceCodeVerifier: {
163+
name: "next-auth.pkce.code_verifier",
164+
options: {
165+
httpOnly: true,
166+
sameSite: "lax",
167+
path: "/",
168+
secure: env.AUTH_URL?.startsWith("https://") ?? false,
169+
maxAge: 60 * 15, // 15 minutes
170+
},
171+
},
172+
},
161173
events: {
162174
createUser: onCreateUser,
163175
signIn: async ({ user, account }) => {

0 commit comments

Comments
 (0)