> ## 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.

# Expire or extend sessions

> Session duration and extending the lifetime of a session.

## Session expiration

Once a session has expired, it can't be reactivated or extended. The user must re-authenticate to create a new session.

The `session_duration_minutes` parameter sets the lifetime of a session from the time it is created:

* **Minimum:** 5 minutes
* **Maximum:** 527,040 minutes (366 days)
* **Default (if blank):**
  * When there is no existing session: 60 minutes
  * When extending an existing session: No change to session expiry

***

## Extend a session

By default, the frontend SDK keeps the `session_jwt` updated, but it does **not** automatically extend the lifetime of the underlying session.

For example, if `session_duration_minutes` is set to 60 minutes, the session will expire 60 minutes after it was created regardless of user activity.

<Steps>
  <Step title="Extend a session's duration">
    Pass a `session_duration_minutes` value to the `session.authenticate()` [method](/api-reference/b2b/frontend-sdks/react/methods/sessions/authenticate-session) or [endpoint](/api-reference/b2b/api/sessions/authenticate-session). The session will be set to expire that many minutes from the time of the call.
  </Step>

  <Step title="Examples" icon="code">
    Techniques could be to set an interval to extend the session's lifetime periodically so the session is automatically extended as long as the user keeps the application open, or setting the expiration based on last user activity.

    <CodeGroup>
      ```javascript lines Via SDK theme={null}
      const extendSession = () => {
        if (stytch.session.getSync()) {
          // Set the session's expiration to 60 minutes from the present
          stytch.session.authenticate({
            session_duration_minutes: 60,
          });
        }
      };

      // Extend the session's lifetime every 10 minutes
      let interval = setInterval(extendSession, 600000);
      window.addEventListener('beforeunload', () => {
        clearInterval(interval);
      });
      ```

      ```python lines Via API theme={null}
      # While getting an authenticated member,
      # set their session's expiration to 60 minutes from the present
      def get_authenticated_member():
        stytch_session = session.get('stytch_session')
        if not stytch_session:
          return None
        try:
          resp = stytch_client.sessions.authenticate(
            session_token=stytch_session,
            session_duration_minutes=60
          )
          return resp.member
        except Exception as e:
          return handle_exception(e)
      ```
    </CodeGroup>
  </Step>
</Steps>
