# Intermittent missing cookie issue resulting in unsuccessful logins

**URL:** <https://community.auth0.com/t/intermittent-missing-cookie-issue-resulting-in-unsuccessful-logins/84813>\
**Category:** Get Help\
**Tags:** nextjs\
**Created:** [June 8, 2022, 2:09pm UTC](https://community.auth0.com/t/intermittent-missing-cookie-issue-resulting-in-unsuccessful-logins/84813 "2022-06-08T14:09:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shyam\_p](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shyam_p/32/37901_2.png) [@shyam\_p](https://community.auth0.com/u/shyam_p)\
**Post date:** [June 8, 2022, 2:09pm UTC](https://community.auth0.com/t/intermittent-missing-cookie-issue-resulting-in-unsuccessful-logins/84813/1 "2022-06-08T14:09:17Z")

</div>

I read this post in detail: [BadRequestError: checks.state argument is missing - #4 by schalk.neethling](https://community.auth0.com/t/badrequesterror-checks-state-argument-is-missing/42609/4), but unfortunately it doesn’t help me at all.  
We’re also running into (very intermittently),

> checks.state argument is missing

We’re using “@auth0/nextjs-auth0”: “^1.9.0”, for a simple app.

Here’s the flow:

1. User pulls up browser and navigates to our website
2. On clicking login /api/auth/login, we’re redirected to our Auth0 tenant
3. User provides credentials and hits login, GET on callback URL is called
4. Occasionally, user is presented with a “checks.state argument is missing”

The problem here is when the GET on callback URL is called, request cookies like (pvisitor, nonce, state, code\_verifier).  
I noticed that in step 1, step 2 etc when I compare requests they are identical. When the error comes up I notice that in step 3 cookies were not passed in the request.

Additional information:

- Seems to happen when browser is starting clean (no cookies or browser history)
- Once user goes back and clicks login then the login works (as mentioned here: [https://github.com/auth0/nextjs-auth0/blob/main/FAQ.md#1-why-do-i-get-a-checksstate-argument-is-missing-error-if-i-try-to-log-in-from-different-tabs](https://github.com/auth0/nextjs-auth0/blob/main/FAQ.md#1-why-do-i-get-a-checksstate-argument-is-missing-error-if-i-try-to-log-in-from-different-tabs)), BUT this is NOT a solution for us and also not the root cause

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 8, 2022, 8:39pm UTC](https://community.auth0.com/t/intermittent-missing-cookie-issue-resulting-in-unsuccessful-logins/84813/4 "2022-06-08T20:39:14Z")

</div>

Hello there @shyam_p welcome to the community!

Thanks for the detailed description of the issue and related resources.

> [@shyam\_p](#):
>
> I notice that in step 3 cookies were not passed in the request.

This is exactly when we would expect to see this error, when the cookies are not picked up on the callback. This can occur for a number of reasons - Have you been able to test this on different browsers? Is there any sort of pattern you can point to there?

I’d probably start by look at the following GH issues which have been opened related to the same error previously:

> <https://github.com/auth0/nextjs-auth0/issues/391#issuecomment-838713434>
>
> \### Describe the problem
> 
> Error handling doesn't seem that graceful - simply e…nding up on a blank page on \`/callback\` that just says \`checks.state argument is missing\`.
> 
> 
> \### What was the expected behavior?
> 
> Probably needs to be passed back to some sort of error handling
> 
> \### Reproduction
> 
> 1. Disable signups in Auth0
> 2. Add api following api route called \`/signup\`:
> \`\`\`ts
> import { handleLogin } from '@auth0/nextjs-auth0';
> import { NextApiRequest, NextApiResponse } from 'next';
> 
> export default async function registerHandler(
> req: NextApiRequest,
> res: NextApiResponse,
> ) {
> handleLogin(req, res, {
> authorizationParams: {
> screen\_hint: 'signup',
> },
> });
> }
> \`\`\`
> 3. Go to \`/api/signup\`
> 
> 
> \### Environment
> 
> 
> \- \*\*Version of this library used:\*\* 1.2.0
> \- \*\*Which framework are you using, if applicable:\*\* next.js
> \- \*\*Other modules/plugins/libraries that might be involved:\*\*
> \- \*\*Any other relevant information you think would be useful:\*\*

> <https://github.com/auth0/nextjs-auth0/issues/340#issuecomment-799344390>
>
> \### Description
> 
> After installing \`nextjs-auth0\` and running the basic example…, I am getting \`checks.state argument is missing\` on the screen as well as in the console.
> 
> \### Reproduction
> 
> 1. Copy \`auth0/nextjs-auth0\` to my local machine at \`nextjs-auth0\`
> 2. \`cd ./nextjs-auth0\`
> 3. \`npm install\`
> 4. \`npm run install:basic\`
> 5. \`cd ./examples/basic-example\`
> 6. Rename \`.env.local.template\` to \`.env.local\` and edit
> 7. \`cd ../..\` to return to the \`nextjs-auth0\` folder
> 8. \`npm run start:basic\`
> 
> \### Expected Results
> 
> Application to run and show Login prompt on screen and no errors on console.
> 
> \### Actual results
> 
> \#### Browser
> 
> \`checks.state argument is missing\`
> 
> \#### Console
> 
> \`\`\`
> \> npm run dev --prefix=examples/basic-example
> 
> \> nextjs-auth0-example@1.0.0 dev D:\\Users\\steve\\Development\\nextjs-auth0-main\\examples\\basic-example
> \> next
> 
> Loaded env from D:\\Users\\steve\\Development\\nextjs-auth0-main\\examples\\basic-example\\.env.local
> ready - started server on 0.0.0.0:3000, url: http://localhost:3000
> event - compiled successfully
> event - build page: /api/auth/\[auth0\]
> wait - compiling...
> event - compiled successfully
> BadRequestError: checks.state argument is missing
> at Object.\<anonymous\> (D:\\Users\\steve\\Development\\nextjs-auth0-main\\examples\\basic-example\\.next\\server\\pages\\api\\auth\\\[auth0\].js:594:19)
> at Generator.throw (\<anonymous\>)
> at rejected (D:\\Users\\steve\\Development\\nextjs-auth0-main\\node\_modules\\tslib\\tslib.js:115:69)
> at runMicrotasks (\<anonymous\>)
> at processTicksAndRejections (internal/process/task\_queues.js:93:5)
> \`\`\`
> 
> \### Environment
> 
> \- \*\*Version of this library used:\*\*: \`@auth0/nextjs-auth0 1.2.1\`
> \- \*\*Version of the platform or framework used, if applicable:\*\* \`next/env 10.0.7\` \`node 14.16.0\` \`npm 6.14.11\`
> \- \*\*Other relevant versions (language, server software, OS, browser):\*\* \`Windows 10 Pro\` \`Brave 1.27.76 Chromium 89\`

(there are a handful of other issues filed in the repo that could be of use as well)

Aside from that, I might recommend attempting to reproduce locally with our Next.js [sample app](https://github.com/auth0-samples/auth0-nextjs-samples/tree/main/Sample-01) - I have been testing myself and have thus far been unable to reproduce. This could be helpful in isolating where the issue is and gives us something to test against.

Keep us posted!

---

<div class="post-metadata">

**Author:** ![shyam\_p](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shyam_p/32/37901_2.png) [@shyam\_p](https://community.auth0.com/u/shyam_p)\
**Post date:** [June 10, 2022, 11:37am UTC](https://community.auth0.com/t/intermittent-missing-cookie-issue-resulting-in-unsuccessful-logins/84813/6 "2022-06-10T11:37:02Z")

</div>

Hi,  
Thanks for the response. It’s not easy to reproduce, only happens on a fresh browser (with all cookies, history deleted). For now we’ve gotten around the problem by redirecting the user back in case of an error so they hit login again and of course it works the second time.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 27, 2022, 1:25am UTC](https://community.auth0.com/t/intermittent-missing-cookie-issue-resulting-in-unsuccessful-logins/84813/7 "2022-07-27T01:25:45Z")

</div>


