cookie icon indicating copy to clipboard operation
cookie copied to clipboard

maxAge is ignored

Open Rashe opened this issue 1 year ago • 0 comments

I try to set maxAge for cookie, but no matter what I do the expiration is always "Session"

The frontend and backend are not on the same domain.

Btw, it works on localhost

My code:

async function login(req, res) {
  try {
    const { email, password } = req.body
    const { token, refreshToken, user } = await authService.login({ email, password })

    res.setCookie("refreshToken", refreshToken, {
  httpOnly: true,
  sameSite: "None",
  secure: true,
  path: "/",
  signed: true,
  maxAge: 30 * 24 * 60 * 60
}).send({ accessToken: token, user })
  } catch (e) {
    console.error(e)
    return res.status(401).send({ error: "Unauthorized" })
  }
}

Rashe avatar Aug 19 '24 18:08 Rashe