# State parameter missing from callback

**URL:** <https://community.auth0.com/t/state-parameter-missing-from-callback/64006>\
**Category:** Get Help\
**Tags:** pkce, bug, callback\
**Created:** [June 7, 2021, 11:43am UTC](https://community.auth0.com/t/state-parameter-missing-from-callback/64006 "2021-06-07T11:43:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tyrone.erasmus](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tyrone.erasmus/32/12877_2.png) [@tyrone.erasmus](https://community.auth0.com/u/tyrone.erasmus)\
**Post date:** [June 7, 2021, 11:43am UTC](https://community.auth0.com/t/state-parameter-missing-from-callback/64006/1 "2021-06-07T11:43:27Z")

</div>

When logging into our site, our users sometimes hit our callback page from Auth0 and don’t get redirected onwards. On closer inspection of why this could be happening, the code looks as follows:

```
if (
        window.location.pathname == callbackPath &&
        window.location.search.includes('code=') &&
        window.location.search.includes('state=')
   ) {
     // Call handleRedirectCallback() and forward user to desired page
}
else if (window.location.search.includes('error=')) {
    // Forward user to error page
}

```

This code generally works well and does not have an `else` case present.

However, sometimes Auth0 redirects the user back to [https://oursite.com/callback?code=JXLEAMf9pBVzWq2L](https://oursite.com/callback?code=JXLEAMf9pBVzWq2L)

Notice that the `state` parameter is missing. We have no idea why this could be happening or if this is a legitimate case that we should be handling.

Any insights would be appreciated.

Further background and setup information below:

- We use Authorization code with PKCE flow
- We use Auth0 SPA JS library and calls to login are done using `loginWithRedirect ()`
- The login is actually successful and can be confirmed in the Auth0 logs
- We use a custom domain
- We have confirmed at least 1 case where this happened with a user using Google social login

---

<div class="post-metadata">

**Author:** ![tyrone.erasmus](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tyrone.erasmus/32/12877_2.png) [@tyrone.erasmus](https://community.auth0.com/u/tyrone.erasmus)\
**Post date:** [June 14, 2021, 9:05am UTC](https://community.auth0.com/t/state-parameter-missing-from-callback/64006/2 "2021-06-14T09:05:38Z")

</div>

Just to close the loop here, this is definitely _not_ an Auth0 bug.

This was caused by our WAF code not URL encoding and inadvertently cutting off the `state` parameter from the URL in one of the redirects. The details aren’t really that interesting other than just knowing that the `state` parameter was coming back from Auth0 correctly.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [June 25, 2021, 11:50am UTC](https://community.auth0.com/t/state-parameter-missing-from-callback/64006/3 "2021-06-25T11:50:07Z")

</div>

Thanks for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 10, 2021, 11:51am UTC](https://community.auth0.com/t/state-parameter-missing-from-callback/64006/4 "2021-07-10T11:51:08Z")

</div>

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