# api.session.setExpiryAt() in post-login action fails to expire session

**URL:** <https://community.auth0.com/t/api-session-setexpiryat-in-post-login-action-fails-to-expire-session/182842>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [February 25, 2025, 6:01pm UTC](https://community.auth0.com/t/api-session-setexpiryat-in-post-login-action-fails-to-expire-session/182842 "2025-02-25T18:01:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![terren](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/terren/32/60385_2.png) [@terren](https://community.auth0.com/u/terren)\
**Post date:** [February 25, 2025, 6:01pm UTC](https://community.auth0.com/t/api-session-setexpiryat-in-post-login-action-fails-to-expire-session/182842/1 "2025-02-25T18:01:41Z")

</div>

Using an post-login action to expire the session to a configured length of time for a particular customer.

Referencing the code below, I see that the relevant setExpiryAt() calls are executed because I see “Session/token expires in…” in the Action Execution logs for my login tests.

And yet my session does not expire. What am I missing?

Here’s the relevant code:

```auto
        ...
    if (sessionTimeoutMinutes) {
      if (!event.session) {
        console.log("!!!!! event.session undefined")
      }
      else if (!event.session.id) {
        console.log(`!!!!! no session.id - session: ${JSON.stringify(event.session)}`)
      } else {
        const expirationTimeMs = sessionTimeoutMinutes * 60 * 1000;
        const expiresAt = Date.now() + expirationTimeMs;
        api.session.setExpiresAt(expiresAt);
        api.refreshToken.setExpiresAt(expiresAt);
        console.log(`>Session/token expires in ${sessionTimeoutMinutes} min at ${(new Date(expiresAt).toISOString())}`);
      }
    }

```

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [February 26, 2025, 6:13pm UTC](https://community.auth0.com/t/api-session-setexpiryat-in-post-login-action-fails-to-expire-session/182842/3 "2025-02-26T18:13:37Z")

</div>

Hi @terren

Welcome to the Auth0 Community!

I would advise to you review the following documentation and knowledge article regarding the matter:

- [Sessions with Actions](https://auth0.com/docs/manage-users/sessions/manage-sessions-actions)
- [User remains logged in after inactivity timeout](https://support.auth0.com/center/s/article/Why-would-Users-Remain-Logged-in-After-the-Inactivity-Timeout)

If you have any other questions or still facing issues after reviewing them, feel free to leave a reply!

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![khushbu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/khushbu/32/76815_2.png) [@khushbu](https://community.auth0.com/u/khushbu)\
**Post date:** [October 30, 2025, 11:13am UTC](https://community.auth0.com/t/api-session-setexpiryat-in-post-login-action-fails-to-expire-session/182842/4 "2025-10-30T11:13:42Z")

</div>

Hi @terren were you able to resolve this issue ? I am facing the same.

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [November 12, 2025, 7:32pm UTC](https://community.auth0.com/t/api-session-setexpiryat-in-post-login-action-fails-to-expire-session/182842/5 "2025-11-12T19:32:35Z")

</div>

Hi @khushbu

I am sorry about the delayed reply.

Do you still experience issues with setting specific session expiration for your application?  
Have you checked out our documentation referenced above?

If yes, could you share more about the application/tenant configuration you have for your session and share your action code?

Kind Regards,  
Nik

---

<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:** [November 26, 2025, 7:32pm UTC](https://community.auth0.com/t/api-session-setexpiryat-in-post-login-action-fails-to-expire-session/182842/6 "2025-11-26T19:32:46Z")

</div>

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