Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PKCE code_verifier cookie was missing in development #9990

Closed
trevorpfiz opened this issue Feb 10, 2024 · 19 comments
Closed

PKCE code_verifier cookie was missing in development #9990

trevorpfiz opened this issue Feb 10, 2024 · 19 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@trevorpfiz
Copy link

Environment

System:
OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
Memory: 7.12 GB / 9.72 GB
Container: Yes
Shell: 5.8 - /usr/bin/zsh
Binaries:
Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
pnpm: 8.15.1 - ~/.local/share/pnpm/pnpm
bun: 1.0.14 - ~/.local/share/pnpm/bun
Watchman: 2024.01.22.00 - /home/linuxbrew/.linuxbrew/bin/watchman

Reproduction URL

https://github.com/trevorpfiz/create-t3-turbo/tree/main

Describe the issue

adding pkceCodeVerifier cookie gives error PKCE code_verifier cookie was missing when using Google or Discord providers in development.

How to reproduce

add

pkceCodeVerifier: {
    name: 'next-auth.pkce.code_verifier',
    options: {
      httpOnly: true,
      sameSite: 'none',
      path: '/',
      secure: process.env.NODE_ENV === 'production',
    },
  },

see error when trying to login in during development with Discord or Google.

Expected behavior

I would expect no error like in production.

@trevorpfiz trevorpfiz added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Feb 10, 2024
@marlon307
Copy link

marlon307 commented Feb 17, 2024

I have the same problem but to authenticate on my subdomains

Link teste

@leo3linbeck
Copy link

Same problem with Auth0 provider.

@daved-gowithhero

This comment has been minimized.

@DuanTranHuy
Copy link

same problem with google provider nextauth v5

@wade-liwei
Copy link

same problem with github provider nextauth v5

@serethomas
Copy link

Same problem with github provider and google provider on next-auth": "5.0.0-beta.17". Has anyone found a solution?

@DeepaPrasanna
Copy link

I am using github provider and followed the documentation as it is and facing the exact same issue!

@zhefciad

This comment has been minimized.

@DeepaPrasanna
Copy link

I have the same problem. Any fixes?

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

i have switched to supabase auth

@jonoise
Copy link

jonoise commented May 20, 2024

remove cookies from the browser. that fixed it for me.

@yeasin2002
Copy link

I'm also getting the same error,
I'm using OAuth and google provider

image

@zhefciad
Copy link

I fixed my problem by changing NEXTAUTH_URL in env.local from 127.0.0.1 to localhost.

@pedrobando
Copy link

remove cookies from the browser. that fixed it for me.

THANK YOUUUUUUUU

@itschip
Copy link

itschip commented Jun 24, 2024

@trevorpfiz did you figure this one out? And if not, can I see your DiscordProvider config?

@trevorpfiz
Copy link
Author

@trevorpfiz did you figure this one out? And if not, can I see your DiscordProvider config?

no. this? https://github.com/MithridHealth/create-t3-turbo/blob/d20d8625f9579e7c90e154d866e7425e48f5a8d1/packages/auth/src/index.ts#L32

@aramshiva
Copy link

Even after removing cookies and changing the NEXTAUTH_URL to localhost:3000, I receive this same error with Notion Provider.

@ThangHuuVu
Copy link
Member

Hello all, I can reproduce what you are reporting with the code example from @trevorpfiz. This isn't an issue of Auth.js though, it is the way cookies work in the browser. If you set the "Same-site" attribute to none, you also need to set "Secure" to true always (See the screenshot below):
Screenshot 2024-08-25 at 13 20 13

Read more at: https://web.dev/articles/samesite-cookies-explained#samesitenone_must_be_secure

pkceCodeVerifier: {
    name: 'next-auth.pkce.code_verifier',
    options: {
      httpOnly: true,
      sameSite: 'none',
      path: '/',
      secure: true,
    },
  },

I'm closing this issue, feel free to open a new issue if you have problems with custom cookies!

@Painwraith
Copy link

@ThangHuuVu Worked for me. Thank you.

@xcode-it
Copy link

xcode-it commented Nov 24, 2024

I struggled a bit when generating the client_secret for apple provider

using npx auth add apple simplifies the process

? Paste Client ID: com.logix.inc
? Paste Key ID: FX73XXXXXX // https://developer.apple.com/account/resources/authkeys/list (Key ID)
? Paste Team ID: 93TPXXXXXX // https://developer.apple.com/account/#/membership/ (Team ID)
? Path to Private Key ./AuthKey_{Key ID}.p8
? Expires in days (default: 180) 180

which will result in

AUTH_APPLE_ID="com.organization.inc"
AUTH_APPLE_SECRET="eyJhbGciOiJFUzI1NiIsImtpZCI6IkZYNzM3RFFISkYifQ....."

__Secure-next-auth.pkce.code_verifier when using ssl in development environment instead of next-auth.pkce.code_verifier

This is how I fixed the issue

import NextAuth from "next-auth";

export default NextAuth({
  debug: true,
  providers: [
    Providers.Apple({
      clientId: process.env.APPLE_CLIENT_ID,
      clientSecret: process.env.APPLE_CLIENT_SECRET,
    }),
  ],
  cookies: {
    pkceCodeVerifier: {
      name: "next-auth.pkce.code_verifier",
      options: {
        httpOnly: true,
        sameSite: "lax",
        path: "/",
        secure: true
      },
    },
  },
});

Source: #6898 (reply in thread)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests