Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 591
ninsau Avatar asked Oct 26 '25 22:10

ninsau


1 Answers

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",
like image 144
LNI Avatar answered Oct 29 '25 16:10

LNI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!