nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
24.75k stars 3.49k forks source link

Next-auth doesn't seem to work in Safari when used with PWA setup #1230

Closed yashSangai closed 3 years ago

yashSangai commented 3 years ago

Describe the bug My Next-Auth application seems to be failing in production mode when I am running it with PWA setup on both macOS/iOS Safari. It throws me Error: Invalid state returned from oAuth provider.

PS:

Configuration Used

const options = {
  providers: [
    Providers.Google({
      clientId: process.env.NEXTAUTH_GOOGLE_ID,
      clientSecret: process.env.NEXTAUTH_GOOGLE_SECRET,
      authorizationUrl:
        "https://accounts.google.com/o/oauth2/v2/auth?prompt=consent&access_type=offline&response_type=code",
    }),
  ],
  jwt: {
    encryption: true,
    secret: process.env.JWT_SECRET,
    signingKey: process.env.SIGNING_KEY,
    encryptionKey: process.env.ENCRYPTION_KEY,
  },
};

Expected behavior Should work normally without the above-mentioned error.

Screenshots or error logs Error log on terminal

[next-auth][error][callback_oauth_error] Error: Invalid state returned from oAuth provider
    at /Users/usr/Documents/app/node_modules/next-auth/dist/server/lib/oauth/callback.js:46:27
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/usr/Documents/app/node_modules/next-auth/dist/server/lib/oauth/callback.js:26:103)
    at _next (/Users/usr/Documents/app/node_modules/next-auth/dist/server/lib/oauth/callback.js:28:194)
    at /Users/usr/Documents/app/node_modules/next-auth/dist/server/lib/oauth/callback.js:28:364
    at new Promise (<anonymous>)
    at /Users/usr/Documents/app/node_modules/next-auth/dist/server/lib/oauth/callback.js:28:97
    at /Users/usr/Documents/app/node_modules/next-auth/dist/server/lib/oauth/callback.js:143:17
    at /Users/usr/Documents/app/node_modules/next-auth/dist/server/routes/callback.js:58:31
    at Generator.next (<anonymous>) 
https://next-auth.js.org/errors#callback_oauth_error

Error on Browser

Screenshot 2021-02-01 at 10 45 40 AM

Feedback Using state: false in options did not help me in fixing the issue. However, after putting this value in the provider whenever I do the login, it again puts me back to the sign-in page.

yashSangai commented 3 years ago

I have upgraded the package to the latest version. But the issue still persists. @iaincollins @balazsorban44 @ndom91 @LoriKarikari Please help me out, I have been stuck with this issue for a long time.

balazsorban44 commented 3 years ago

@yashSangai We appreciate your enthusiasm about this project, but tagging core maintainers won't accelerate the process of fixing your problem! We work on many different issues at the same time, and we have different priorities. I cannot speak for anyone else, but I don't have access to any macOS/iOS/Safari devices, so I cannot confirm your issue to begin with. The code is fully available, so if you have the time/knowledge to debug our source, we would really appreciate any kind of help!

This issue is a duplicate #952 anyway, so going to close this for now. Please follow #952 for any development.