Err_callback_handler_failure

I am trying to create a simple/sample NextJs app with OAuth login
I downloaded the code provided by the dashboard whilst creating firs sample APP using NextJs

I configured and copied environment variables mentioned exactly in https://auth0.com/docs/quickstart/webapp/nextjs/interactive article.

I ran npm install npm run dev and started the app.

my NextJs Application uses pages directory and /api/auth/[auth0].ts, api handler is simply

import {handleAuth} from “@auth0/nextjs-auth0”;

export default handleAuth();

when I click Login, I get redirected to Auth0 screen for signin/SignUp.

It then redirects me to my application on

http://localhost:3000/api/auth/callback?code=tCpAwy1x5umkry1TQ_IQMq9-wiDuwIToM8Lq0e23FdHAI&state=eyJyZXR1cm5UbyI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMCJ9

with following error on nextJs Server console!!

CallbackHandlerError: Callback handler failed. CAUSE: Missing state cookie from login request (check login URL, callback URL and cookie config).
at CallbackHandlerError.AuthError [as constructor] (/Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/@auth0/nextjs-auth0/dist/utils/errors.js:34:16)
at CallbackHandlerError.HandlerError [as constructor] (/Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/@auth0/nextjs-auth0/dist/utils/errors.js:110:23)
at new CallbackHandlerError (/Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/@auth0/nextjs-auth0/dist/utils/errors.js:138:28)
at /Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/@auth0/nextjs-auth0/dist/handlers/callback.js:42:31
at step (/Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/tslib/tslib.js:195:27)
at Object.throw (/Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/tslib/tslib.js:176:57)
at rejected (/Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/tslib/tslib.js:167:69)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: ‘ERR_CALLBACK_HANDLER_FAILURE’,
cause: MissingStateCookieError: Missing state cookie from login request (check login URL, callback URL and cookie config).
at new MissingStateCookieError (/Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/@auth0/nextjs-auth0/dist/auth0-session/utils/errors.js:39:16)
at /Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/@auth0/nextjs-auth0/dist/auth0-session/handlers/callback.js:30:63
at step (/Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/tslib/tslib.js:195:27)
at Object.next (/Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/tslib/tslib.js:176:57)
at fulfilled (/Users/hiteshkhatri/Documents/BMI/next-auth0-3/node_modules/tslib/tslib.js:166:62)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
expose: true,
statusCode: 400,
status: 400
},
status: 400
}

I have tried to upgrade / downgrade Auth0 version(s) …but nothing works!!

This topic has been discussed here multiple times … but everyone’s causes seems to be different!

2 Likes

Hi @hitesh.khatri,

It looks like the state parameter was not passed in the login request. This is also justified by the response URL: http://localhost:3000/api/auth/callback?code=tCpAwy1x5umkry1TQ_IQMq9-wiDuwIToM8Lq0e23FdHAI&state=eyJyZXR1cm5UbyI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMCJ9

You should expect something like the following when passing the state parameter in the /authorize request:
http://localhost:3000/api/auth/callback?code=tCpAwy1x5umkry1TQ_IQMq9-wiDuwIToM8Lq0e23FdHAI&state=eyJyZXR1cm5UbyI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMCJ9&state=yourState

Thanks,
Rueben

1 Like

Hi @hitesh.khatri ,
What was the fix you implemented? There’s quite a few of us stuck with this problem…

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.