# How to redirect users to same page after log in

**URL:** <https://community.auth0.com/t/how-to-redirect-users-to-same-page-after-log-in/68777>\
**Category:** Get Help\
**Tags:** redirect\
**Created:** [August 30, 2021, 5:45am UTC](https://community.auth0.com/t/how-to-redirect-users-to-same-page-after-log-in/68777 "2021-08-30T05:45:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hussamkhatib](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hussamkhatib/32/30961_2.png) [@hussamkhatib](https://community.auth0.com/u/hussamkhatib)\
**Post date:** [August 30, 2021, 5:45am UTC](https://community.auth0.com/t/how-to-redirect-users-to-same-page-after-log-in/68777/1 "2021-08-30T05:45:01Z")

</div>

Is there a way a user after successful log in redirect to the exact same page .  
I am able to redirect to any one page by hardcoding the route.  
But in my case I want the user to redirect to exactly the same page .  
Thanks ,  
Hussam

---

<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:** [August 30, 2021, 10:51am UTC](https://community.auth0.com/t/how-to-redirect-users-to-same-page-after-log-in/68777/2 "2021-08-30T10:51:28Z")

</div>

Hey there!

Can you explain a bit more about the usecase? Why you want to redirect logged in user to a page where they can login?

---

<div class="post-metadata">

**Author:** ![hussamkhatib](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hussamkhatib/32/30961_2.png) [@hussamkhatib](https://community.auth0.com/u/hussamkhatib)\
**Post date:** [September 4, 2021, 11:47am UTC](https://community.auth0.com/t/how-to-redirect-users-to-same-page-after-log-in/68777/3 "2021-09-04T11:47:34Z")

</div>

I think you got my question wrong.  
Suppose I am in `/browse` route and unauthenticated .  
If I click on login button from the navigation bar , I will be taken too login page . after login is done .  
I want the user to go back to `/browse` page only .  
Similarly for any route , the user should stay on that route only after the login is completed .

Coming to the use case .  
Coinsider you are buying shoes online , that route will be `/products/shoes`.  
Something like .As he click on buy button , he is asked to login .After the log in is done , you wouldn’t want the user to go back to landing page right ?

---

<div class="post-metadata">

**Author:** ![praveen.addepally](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/praveen.addepally/32/14314_2.png) [@praveen.addepally](https://community.auth0.com/u/praveen.addepally)\
**Post date:** [September 5, 2021, 5:22am UTC](https://community.auth0.com/t/how-to-redirect-users-to-same-page-after-log-in/68777/4 "2021-09-05T05:22:52Z")

</div>

Hello Hussam,  
Thanks for explaining your usecase & it looks like you’re looking to restore the application state after user successfully authenticated.

Below page has details on how to implement it

> **[Prevent Attacks and Redirect Users with OAuth 2.0 State Parameters](https://auth0.com/docs/secure/attack-protection/state-parameters)**
>
> Describes how to use the state parameter in authentication requests to help prevent CSRF attacks and restore state

However, depending on the Auth0 SDKs you’re using this is supported OOB, for example to implement in auth0-spa-js SDK you could leverage **appState**

[https://auth0.github.io/auth0-spa-js/interfaces/redirectloginresult.html#appstate](https://auth0.github.io/auth0-spa-js/interfaces/redirectloginresult.html#appstate)

---

<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:** [September 20, 2021, 11:54am UTC](https://community.auth0.com/t/how-to-redirect-users-to-same-page-after-log-in/68777/5 "2021-09-20T11:54:35Z")

</div>

Thanks a lot @praveen.addepally for helping on that!

---

<div class="post-metadata">

**Author:** ![julius.veer](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/julius.veer/32/13081_2.png) [@julius.veer](https://community.auth0.com/u/julius.veer)\
**Post date:** [September 25, 2021, 3:40pm UTC](https://community.auth0.com/t/how-to-redirect-users-to-same-page-after-log-in/68777/6 "2021-09-25T15:40:40Z")

</div>

did you find a solution? because I’m struggling with the exact same problem right now…

---

<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:** [September 27, 2021, 7:42am UTC](https://community.auth0.com/t/how-to-redirect-users-to-same-page-after-log-in/68777/7 "2021-09-27T07:42:13Z")

</div>

Hey there Julius!

Have you had a chance to check what @praveen.addepally shared?

---

<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:** [September 30, 2021, 9:30am UTC](https://community.auth0.com/t/how-to-redirect-users-to-same-page-after-log-in/68777/8 "2021-09-30T09:30:10Z")

</div>

Ping ping friendly ping 🙂

---

<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:** [October 15, 2021, 9:30am UTC](https://community.auth0.com/t/how-to-redirect-users-to-same-page-after-log-in/68777/9 "2021-10-15T09:30:40Z")

</div>

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