> ## Documentation Index
> Fetch the complete documentation index at: https://stytch.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Hydrating sessions

> Hydrate the frontend session state from the backend.

## Use case

* **Backend-initiated session changes:** Ensure your frontend session state stays in sync when sessions are created or updated on the backend.

***

## Session hydration

**1. Update session tokens**

Provide both the active `session_token` and `session_jwt` to the `session.updateSession()` method to prime the frontend with a valid set of tokens.

**2. Make an authenticate session call**

Authenticate the session using the `session.authenticate()` method to validate the updated session tokens.

**3. Example**

```javascript lines theme={null}
export const hydrateSession = () => {
    stytch.session.updateSession({
        session_token: 'ACTIVE_SESSION_TOKEN',
        session_jwt: 'ACTIVE_SESSION_JWT',
    });

    stytch.session.authenticate();
};
```

> [!NOTE]
>
> When `HttpOnly` cookies are enabled for your Stytch project, the Sessions Update method only works if there isn't an existing session token set in an `HttpOnly` cookie.
>
> * If `HttpOnly` cookies are enabled, make sure your SDK client's `cookieOptions` are configured to match the domain and cookie names used by Stytch's backend.
>
> * Alternatively, you can override the session cookies via response headers from your backend. Be sure to still make a frontend authenticate session call.
