# React application get Auth0 session from cookie

**URL:** <https://community.auth0.com/t/react-application-get-auth0-session-from-cookie/106974>\
**Category:** Get Help\
**Tags:** authentication-sessions, sessions\
**Created:** [May 16, 2023, 2:05am UTC](https://community.auth0.com/t/react-application-get-auth0-session-from-cookie/106974 "2023-05-16T02:05:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![notronwest](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/notronwest/32/45778_2.png) [@notronwest](https://community.auth0.com/u/notronwest)\
**Post date:** [May 16, 2023, 2:05am UTC](https://community.auth0.com/t/react-application-get-auth0-session-from-cookie/106974/1 "2023-05-16T02:05:58Z")

</div>

We are hosting a React application in S3 via a Cloudfront distribution. The Cloudfront distribution uses a Lambda@Edge script to forward unauthenticated users to Auth0.

Once authenticated, they are redirected to the React application.

The Cloudfront distribution and React application live in the same subdomain and thus we have access to the JWT (currently being set in a cookie).

We would like to ‘automatically’ hydrate the session in the React app and have tried code similar to the following:

```auto
// component ...

const { loginWithRedirect, isAuthenticated } = useAuth0();

  useEffect(() => {
    if (!isAuthenticated) {
      loginWithRedirect();
    }
  }, [isAuthenticated, loginWithRedirect]);

// component ...

```

And it seems to work – however once the `loginWithRedirect()` method finishes – the application continually refreshes – as if isAuthenticated is never set.

Any thoughts?

---

<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:** [May 17, 2023, 2:00pm UTC](https://community.auth0.com/t/react-application-get-auth0-session-from-cookie/106974/4 "2023-05-17T14:00:42Z")

</div>

Hey there,

Correct me if I misunderstood you, but what you would like to achieve here is to make use of _created by Auth0 server session cookie_ which is stored later in the end user browser.

Also, if you reference to a **S** ingle **P** age **A** pplication (residing entirely in a browser and utilising the Authorisation Code Flow) you may encounter an expected, related to security technologies like ITP, limitations - some browsers will reject to store cookies considered as third-party (in case of SPAs, auth0 cookies are considered as third-party cookies).

For the seamless access to resources it’s recommended that browser-based flows must use [Refresh Token Rotation](https://auth0.com/docs/secure/tokens/refresh-tokens/refresh-token-rotation), which provides a secure method for using refresh tokens in SPAs.

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

If you meant something else or have additional questions, please let me know! And have a good day!

---

<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:** [May 31, 2023, 2:01pm UTC](https://community.auth0.com/t/react-application-get-auth0-session-from-cookie/106974/5 "2023-05-31T14:01:22Z")

</div>

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