Skip to content

Static maxAge #767

Closed Answered by vvo
jordanpurinton asked this question in Q&A
Discussion options

You must be logged in to vote

Hey there, I just found a solution how to do this.
First, on login, you compute a date in milliseconds you want to use as the date you want the cookie to expire, no matter what. Then you store this value in the session object directly, and you update the config, something like:

function login() {
  const session = await getIronSession<SessionData>(cookies(), sessionOptions);
  const expirationTimestamp = Date.now() + 30 * 24 * 60 * 1000;
  session.isLoggedIn = true;
  session.counter = 0;
  session.expirationTimestamp = expirationTimestamp;

  session.updateConfig({
    ...sessionOptions,
    cookieOptions: {
      ...sessionOptions.cookieOptions,
      maxAge: undefined,
      expires: new 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by vvo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #659 on June 14, 2024 13:15.