Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
Iron-session set cookie maxAge

I'm trying to set up a Next JS app with iron-session and a 'remember me' function, whereby if the user ticks the remember me box on the login form then the maxAge of the iron-session cookie is set to a week rather than my default value of 24 hours.

However, I can't work out a way to set the value programatically. I've tried the following but I get 'rememberMe not defined' on the ternary.

export default withIronSessionApiRoute(
  async function loginRoute(req, res) {
    const { username, password, rememberMe } = req.body;
    await req.session.save();
    return res.status(200).send('Logged in');
  },
  {
    cookieName: 'DEMOAUTH',
    password: 'PmsDH2Hm09rP7XRJkuo7TKDQXtowtBjurW66RUzU',
    ttl: rememberMe ? 60 * 60 * 24 * 7 : 60 * 60 * 24,
  }
);

EDIT following Jesse's comment - I tweaked slightly, adding a const rememberMe = true to check the value was definitely being set and I get the same behaviour

export default withIronSessionApiRoute(
  async function loginRoute(req, res) {
    const { username, password } = req.body;
    const rememberMe = true;
    await req.session.save();
    return res.status(200).send('Logged in');
  },
  {
    cookieName: 'DEMOAUTH',
    password: 'PmsDH2Hm09rP7XRJkuo7TKDQXtowtBjurW66RUzU',
    ttl: rememberMe ? 60 * 60 * 24 * 7 : 60 * 60 * 24,
  }
);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

rememberMe is defined outside of the scope in which you are trying to use it. That's why it's not defined.

As far as I know, it's not possible to change the iron-session configuration based on the request body as of now, but here is an issue requesting that feature.

Maybe for this specific case what you can do is create two API endpoints with different cookie configurations.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda