# Getting invalid state on redirect

**URL:** <https://community.auth0.com/t/getting-invalid-state-on-redirect/110901>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [July 10, 2023, 4:34pm UTC](https://community.auth0.com/t/getting-invalid-state-on-redirect/110901 "2023-07-10T16:34:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anupamc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anupamc/32/48716_2.png) [@Anupamc](https://community.auth0.com/u/Anupamc)\
**Post date:** [July 10, 2023, 4:34pm UTC](https://community.auth0.com/t/getting-invalid-state-on-redirect/110901/1 "2023-07-10T16:34:24Z")

</div>

I am building a react application, as per requirement the app will run on localhost:3400, after login I want to redirect user to org1.localhost:3400. Redirection to org1.localhost:3400 is working, But getting ‘invalid state’, Please let me know how this can be resolved.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [July 10, 2023, 10:19pm UTC](https://community.auth0.com/t/getting-invalid-state-on-redirect/110901/3 "2023-07-10T22:19:38Z")

</div>

Hi @Anupamc,

Thanks for reaching out to the Auth0 Community!

An invalid state error happens when the returned state value does not match the state value that was passed in the initial login request. This is explained in more detail in [this related post](https://community.auth0.com/t/invalid-state-on-reload-auth0-callback-url-using-auth0-spa-js-and-angular-8/36469/10).

Could you please confirm if the state value passed in the login request matches the state value in the response?

---

<div class="post-metadata">

**Author:** ![Anupamc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anupamc/32/48716_2.png) [@Anupamc](https://community.auth0.com/u/Anupamc)\
**Post date:** [July 10, 2023, 1:17pm UTC](https://community.auth0.com/t/getting-invalid-state-on-redirect/110901/4 "2023-07-10T13:17:32Z")

</div>

My user is login to the application using localhost:3000, after getting authenticated from auth0 I want the user to be redirected to new.locahost:3000. when passing ‘new.localhost:3000’ the url is opening after the authentication but getting ‘Invalid State’ error. Please let me know how to fix this.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [July 10, 2023, 10:23pm UTC](https://community.auth0.com/t/getting-invalid-state-on-redirect/110901/5 "2023-07-10T22:23:18Z")

</div>

Hi @Anupamc,

I have merged your first post on this thread on having an invalid state to keep our conversation in one place.

Thanks!

---

<div class="post-metadata">

**Author:** ![Anupamc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anupamc/32/48716_2.png) [@Anupamc](https://community.auth0.com/u/Anupamc)\
**Post date:** [July 11, 2023, 10:06am UTC](https://community.auth0.com/t/getting-invalid-state-on-redirect/110901/6 "2023-07-11T10:06:24Z")

</div>

Hi @rueben.tiow , thanks for your reply. I am using below npm package.  
import { useAuth0 } from “@auth0/auth0-react”

I dont see any option to pass state in loginwithRedirect function. how can I pass state value in the initial login request here.

onClick={() =\> loginWithRedirect()}

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [July 11, 2023, 11:59pm UTC](https://community.auth0.com/t/getting-invalid-state-on-redirect/110901/7 "2023-07-11T23:59:55Z")

</div>

Hi @Anupamc,

Thanks for following up.

Could you please share the exact code and steps you took in your tests that led to an invalid state error?

And if possible, could you please [capture the login events in a HAR file](https://auth0.com/docs/troubleshoot/troubleshooting-tools/generate-and-analyze-har-files) and send them to me as a direct message to investigate further?

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![Anupamc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anupamc/32/48716_2.png) [@Anupamc](https://community.auth0.com/u/Anupamc)\
**Post date:** [July 12, 2023, 4:52pm UTC](https://community.auth0.com/t/getting-invalid-state-on-redirect/110901/8 "2023-07-12T16:52:21Z")

</div>

HI @rueben.tiow , I am using sample react app provided by Auth0.

> <https://github.com/auth0-samples/auth0-react-samples/tree/master/Sample-01>
>
> //github.com/auth0-samples/auth0-react-samples/tree/master/Sample-01

updated the providerConfig as mentioned below. In my case both localhost:3400 and org1.localhost:3400 are pointing to same application.

const providerConfig = {  
domain: config.domain,  
clientId: config.clientId,  
onRedirectCallback,  
authorizationParams: {  
redirect\_uri: ‘[http://org1.localhost:3400](http://org1.localhost:3400)’,  
organization:‘org\_g8jXXXXXXXTU5u’,  
…(config.audience ? { audience: config.audience } : null),  
},  
};

After login getting successfully redirected to [http://org1.localhost:3400/?code=XXXX&state=XXXX](http://org1.localhost:3400/?code=XXXX&state=XXXX)  
but getting invalid state error.

PFA HAR file  
[org1.localhost.har](https://community.auth0.com/404) (6.3 MB)

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [July 19, 2023, 12:30am UTC](https://community.auth0.com/t/getting-invalid-state-on-redirect/110901/9 "2023-07-19T00:30:25Z")

</div>

Hi @Anupamc,

Thanks for your reply.

After looking at your HAR file carefully, I see that the returned `state` parameter matches the one from the initial login request.

And when testing this on my end, I could not reproduce the error with the Auth0 React SDK.

One workaround I would recommend is to go directly to the [Auth0 React SDK Quickstarts: Login](https://auth0.com/docs/quickstart/spa/react) page and log in to your Auth0 account.

On there, you should have an option to **Download Sample**.  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/8/8/8890e3e858ee88cd3674c886c0c6f989c8456e4d.png)

A popup window should appear, giving you the option to select the application you would like this sample to be configured for:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/9/0/907b368869306bb8e351a85ab8b93c2f914671c4.png)

Then following the provided instructions, you should be able to run the sample application without any issues.

Could you please give this a try and let me know how it goes?

Thanks,  
Rueben

---

<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:** [August 2, 2023, 12:30am UTC](https://community.auth0.com/t/getting-invalid-state-on-redirect/110901/10 "2023-08-02T00:30:28Z")

</div>

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