# Invalid state error caused by $store not retaining data

**URL:** <https://community.auth0.com/t/invalid-state-error-caused-by-store-not-retaining-data/115092>\
**Category:** Get Help\
**Tags:** authentication-sessions, sessions\
**Created:** [August 31, 2023, 2:38am UTC](https://community.auth0.com/t/invalid-state-error-caused-by-store-not-retaining-data/115092 "2023-08-31T02:38:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hubert\_r](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hubert_r/32/50415_2.png) [@hubert\_r](https://community.auth0.com/u/hubert_r)\
**Post date:** [August 31, 2023, 2:38am UTC](https://community.auth0.com/t/invalid-state-error-caused-by-store-not-retaining-data/115092/1 "2023-08-31T02:38:11Z")

</div>

I’m integrating auth0 with an existing site running on PHP. So I’m using the auth0-php SDK.

It’s all working fine on my local environment. I call `$auth0->login()` to get the login URL, I redirect there, and then it calls the callback endpoint. That in turns calls `$auth0->exchange()`, and then I get the user with `$auth0->getUser()`. All good!

But then when deployed on our production environment (on Platform.sh), it doesn’t work. When `$auth0->exchange()` is called, it comes back an invalid state error.

I’ve done quite a bit of research and debugging, and here is what I’ve found:

When we call `$auth0->login()`, it creates the `$state` string, and puts it in the internal storage: `$store->store('state', (string) $state)`

When we call `$auth0->exchange()`, it then tries to retrieve that state:  
`$verified = (null !== $state && $store->verify('state', $state))`

And at that point `$store` is empty - it hasn’t retained any of the values. Somehow when we go to the login URL and come back to our site, `$store` is then empty.

I’ve also noticed that on my local environment I get three cookies: `auth0_session_0`, `auth0_session_1`, and some session cookie. On the prod environment I only get one cookie: `auth0_transient_0`

Any idea what could be the cause of this in our production environment? Some PHP setting of some sort?

---

<div class="post-metadata">

**Author:** ![hubert\_r](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hubert_r/32/50415_2.png) [@hubert\_r](https://community.auth0.com/u/hubert_r)\
**Post date:** [August 31, 2023, 11:06pm UTC](https://community.auth0.com/t/invalid-state-error-caused-by-store-not-retaining-data/115092/2 "2023-08-31T23:06:26Z")

</div>

Never mind, I found the issue. Cookies were restricted on Platform.sh. I’ve allowed the auth0 cookies and it now all works fine.

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [September 1, 2023, 6:37am UTC](https://community.auth0.com/t/invalid-state-error-caused-by-store-not-retaining-data/115092/3 "2023-09-01T06:37:00Z")

</div>

Thanks for sharing with the rest of community @hubert_r !

---

<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:** [September 15, 2023, 6:37am UTC](https://community.auth0.com/t/invalid-state-error-caused-by-store-not-retaining-data/115092/4 "2023-09-15T06:37:32Z")

</div>

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