NextAuth + AWS Cognito - message: 'nonce mismatch, expected undefined, got:
Asked Answered
D

1

4

I'm using nextjs 12.1.6, nextauth ^4.5.0, cognito to create social sign ins. After successful sign in on the cognito Hosted UI, I get redirected to my nextjs app with this error in the url api/auth/signin?error=OAuthCallback. I'm not sure what the problem is. Here is the log I get:enter image description here

here's the nextjs app: enter image description here

My cognito callbacks: enter image description here

My nextauth config :enter image description here

Dyadic answered 16/6, 2022 at 20:45 Comment(2)
Please make sure to post code and errors as text directly to the question (and not as images), and format them appropriately.Koumis
Related GH discussion: github.com/nextauthjs/next-auth/discussions/3551.Koumis
B
1

I have been able to get this to work by using the following code:

 providers: [
    CognitoProvider({
      clientId: process.env.COGNITO_CLIENT_ID,
      clientSecret: process.env.COGNITO_CLIENT_SECRET,
      issuer: process.env.COGNITO_ISSUER,
      checks: ['nonce']
    })
]

This is with:

    "next": "^14.1.4",
    "next-auth": "^4.24.5",
Bespoke answered 27/3 at 0:10 Comment(1)
Had a similar problem, checks: ['nonce'] did the trick.Adamite

© 2022 - 2024 — McMap. All rights reserved.