# I want to set session expiry specific to a user

**URL:** <https://community.auth0.com/t/i-want-to-set-session-expiry-specific-to-a-user/193936>\
**Category:** Get Help\
**Tags:** signup-prompt-new-experience, login-experience\
**Created:** [October 30, 2025, 1:29pm UTC](https://community.auth0.com/t/i-want-to-set-session-expiry-specific-to-a-user/193936 "2025-10-30T13:29:39Z")\
**Posts on this page:** 3\
**Page:** 1

<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, 1:29pm UTC](https://community.auth0.com/t/i-want-to-set-session-expiry-specific-to-a-user/193936/1 "2025-10-30T13:29:39Z")

</div>

I want to set session expiry specific to a user based on some rules stored in my database.

I tried following the post login actions article : [https://auth0.com/docs/manage-users/sessions/manage-sessions-actions](https://auth0.com/docs/manage-users/sessions/manage-sessions-actions)

The problem is that is setting session expiry for that particular post-login interaction.

1. I want to update session expiry for user’s complete session. Any way to do that ?
2. Anyway to know the users last login time. So that I can set the session expiry on that.

const nowInSeconds = Math.floor(Date.now() / 1000); → I want to use login time instead of .now()

api.session.setIdleExpiresAt(nowInSeconds + 10);

api.session.setExpiresAt(nowInSeconds + 10);

console.log(`Session will expire at ${nowInSeconds + 15}`);

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [October 31, 2025, 4:32pm UTC](https://community.auth0.com/t/i-want-to-set-session-expiry-specific-to-a-user/193936/3 "2025-10-31T16:32:54Z")

</div>

Hi @khushbu,

Welcome back to the Auth0 Community!

> [@khushbu](#):
>
> Anyway to know the users last login time. So that I can set the session expiry on that.

You have identified correctly how to get the user’s last login, since the Date.now() function takes place right after a successful login since it executes in a Post-Login Action. This could also be checked using the [event.session.created\_at](https://auth0.com/docs/customize/actions/explore-triggers/signup-and-login-triggers/login-trigger/post-login-event-object) option ( note that this option is only available for Enterprise Customers )

> [@khushbu](#):
>
> I want to update session expiry for user’s complete session. Any way to do that ?

Since you are mentioning ‘complete session’, my guess is that you are trying to set an absolute lifetime for the user session. You action’s code looks correct to me, but a more robust action code that should work for your use case could be similar to:

```auto
exports.onExecutePostLogin = async (event, api) => {

const currentTimeMs = new Date().getTime(); // Date.now() would work as well
const tenSeconds = 10 * 1000;
const absolute = currentTimeMs + tenSeconds;
api.session.setExpiresAt(absolute);
api.refreshToken.setExpiresAt(absolute);
console.log(`setting expiration: `, absolute);
};

```

You could also check if the session exists, but please note that, but also be aware that [Session ID in a Post Login Action](https://support.auth0.com/center/s/article/Session-ID-in-a-post-login-action) is listed as options and can be undefined. Please also not that **the API.session.setIdleExpiresAt(idle)** method sets the session inactivity timeout for the current interaction. If the method is not reapplied, subsequent successful interactions will override the inactivity timeout using the session inactivity timeout settings.

I hope this helps and if you have further questions please let me know!  
Thank you,  
Remus

---

<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 14, 2025, 4:33pm UTC](https://community.auth0.com/t/i-want-to-set-session-expiry-specific-to-a-user/193936/4 "2025-11-14T16:33:48Z")

</div>

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