sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.24k stars 159 forks source link

OAuthCallback error on Netlify #435

Closed sun-ergo-s closed 11 months ago

sun-ergo-s commented 1 year ago

Environment

This is my localhost environment:

I don't know Netlify environment.

Reproduction

https://github.com/sun-ergo-s/testing-nuxt-on-netlify

Deployed on Netlify: https://whimsical-biscotti-346a06.netlify.app/

Describe the bug

I have a clean install of Nuxt@3.5.3 application with @sidebase/nuxt-auth@0.5.0 (also tried 0.6.0-beta.2).

After deploying on Netlify I got the OAuthCallback error using Google/Facebook provider in URL after redirect.

On localhost everything works fine.

I have defined AUTH_ORIGIN and NEXTAUTH_URL variables on Netlify and also in config file:

auth: {
    origin: process.env.AUTH_ORIGIN
}

Additional context

Works on Vercel. I also tried this solution but it didn't work:

add cookies config

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

Originally posted by @desenmeng in https://github.com/nextauthjs/next-auth/discussions/6898#discussioncomment-5308820

Logs

netlify-error

bweisel commented 1 year ago

+1 on this -- I'm hitting the same issue. Works on Vercel just fine though.

bweisel commented 1 year ago

@sun-ergo-s I figured out a fix for this!

The issue was actually in Nitro -- it was not handling the Set-Cookie header properly. Here is the fix: https://github.com/unjs/nitro/pull/1452

You can pull in the latest, edge version of Nitro following the steps here: https://github.com/Hebilicious/authjs-nuxt/issues/51#issuecomment-1653419171

Specifically adding to my package.json file:

"resolutions": {
    "nitropack": "npm:nitropack-edge@latest"
  },