fix: update token expiration handling to use correct time units for cookies

This commit is contained in:
Marco Pedone 2025-09-04 12:38:49 +02:00
parent d5894f6ec4
commit 128088abfd
3 changed files with 7 additions and 7 deletions

View file

@ -137,7 +137,7 @@ const refreshAuthToken = async (
); );
response.cookies.set(TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_NAME, newAccessToken, { response.cookies.set(TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_NAME, newAccessToken, {
expires: add(new Date(), { expires: add(new Date(), {
minutes: TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_EXPIRY, hours: TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_EXPIRY,
}), }),
...TOKEN_CONFIG.COOKIE_OPTIONS, ...TOKEN_CONFIG.COOKIE_OPTIONS,
//secure: env.NODE_ENV === "production", //secure: env.NODE_ENV === "production",

View file

@ -1,9 +1,9 @@
export const TOKEN_CONFIG = { export const TOKEN_CONFIG = {
ACCESS_TOKEN_COOKIE_NAME: "access_token", ACCESS_TOKEN_COOKIE_NAME: "access_token",
REFRESH_TOKEN_COOKIE_NAME: "refresh_token", REFRESH_TOKEN_COOKIE_NAME: "refresh_token",
ACCESS_TOKEN_EXPIRY: "5m", ACCESS_TOKEN_EXPIRY: "1h",
REFRESH_TOKEN_EXPIRY: "7d", REFRESH_TOKEN_EXPIRY: "7d",
ACCESS_TOKEN_COOKIE_EXPIRY: 5, ACCESS_TOKEN_COOKIE_EXPIRY: 1,
REFRESH_TOKEN_COOKIE_EXPIRY: 7, REFRESH_TOKEN_COOKIE_EXPIRY: 7,
COOKIE_OPTIONS: { COOKIE_OPTIONS: {
httpOnly: true, httpOnly: true,

View file

@ -143,7 +143,7 @@ export const logIn = async ({
await setCookie(TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_NAME, accessToken, { await setCookie(TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_NAME, accessToken, {
...TOKEN_CONFIG.COOKIE_OPTIONS, ...TOKEN_CONFIG.COOKIE_OPTIONS,
expires: add(new Date(), { expires: add(new Date(), {
minutes: TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_EXPIRY, hours: TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_EXPIRY,
}), }),
req, req,
res, res,
@ -151,7 +151,7 @@ export const logIn = async ({
await setCookie(TOKEN_CONFIG.REFRESH_TOKEN_COOKIE_NAME, refreshToken, { await setCookie(TOKEN_CONFIG.REFRESH_TOKEN_COOKIE_NAME, refreshToken, {
...TOKEN_CONFIG.COOKIE_OPTIONS, ...TOKEN_CONFIG.COOKIE_OPTIONS,
expires: add(new Date(), { expires: add(new Date(), {
minutes: TOKEN_CONFIG.REFRESH_TOKEN_COOKIE_EXPIRY, days: TOKEN_CONFIG.REFRESH_TOKEN_COOKIE_EXPIRY,
}), }),
req, req,
res, res,
@ -206,7 +206,7 @@ export const swapAuth = async ({
await setCookie(TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_NAME, accessToken, { await setCookie(TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_NAME, accessToken, {
...TOKEN_CONFIG.COOKIE_OPTIONS, ...TOKEN_CONFIG.COOKIE_OPTIONS,
expires: add(new Date(), { expires: add(new Date(), {
minutes: TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_EXPIRY, hours: TOKEN_CONFIG.ACCESS_TOKEN_COOKIE_EXPIRY,
}), }),
req, req,
res, res,
@ -214,7 +214,7 @@ export const swapAuth = async ({
await setCookie(TOKEN_CONFIG.REFRESH_TOKEN_COOKIE_NAME, refreshToken, { await setCookie(TOKEN_CONFIG.REFRESH_TOKEN_COOKIE_NAME, refreshToken, {
...TOKEN_CONFIG.COOKIE_OPTIONS, ...TOKEN_CONFIG.COOKIE_OPTIONS,
expires: add(new Date(), { expires: add(new Date(), {
minutes: TOKEN_CONFIG.REFRESH_TOKEN_COOKIE_EXPIRY, days: TOKEN_CONFIG.REFRESH_TOKEN_COOKIE_EXPIRY,
}), }),
req, req,
res, res,