From e8233dfd9ff6d727a7fff235a9d42added42cfc9 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Tue, 3 May 2022 10:26:12 +0200 Subject: [PATCH] refactor: setup maxAge in seconds --- packages/next/server/web/spec-extension/cookies.ts | 3 +-- test/unit/web-runtime/cookies.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/next/server/web/spec-extension/cookies.ts b/packages/next/server/web/spec-extension/cookies.ts index 3d60c5499d22..f6cf48029a7b 100644 --- a/packages/next/server/web/spec-extension/cookies.ts +++ b/packages/next/server/web/spec-extension/cookies.ts @@ -5,8 +5,7 @@ const normalizeCookieOptions = (options: CookieSerializeOptions) => { options = Object.assign({}, options) if (options.maxAge) { - options.expires = new Date(Date.now() + options.maxAge) - options.maxAge /= 1000 + options.expires = new Date(Date.now() + options.maxAge * 1000) } if (options.path == null) { diff --git a/test/unit/web-runtime/cookies.test.ts b/test/unit/web-runtime/cookies.test.ts index 7ee620cd7018..7eca76da0d45 100644 --- a/test/unit/web-runtime/cookies.test.ts +++ b/test/unit/web-runtime/cookies.test.ts @@ -55,7 +55,7 @@ it('.set with options', async () => { const options: CookieSerializeOptions = { path: '/', - maxAge: 1000 * 60 * 60 * 24 * 7, + maxAge: 60 * 60 * 24 * 7, httpOnly: true, sameSite: 'strict', domain: 'example.com', @@ -65,7 +65,7 @@ it('.set with options', async () => { expect(options).toStrictEqual({ path: '/', - maxAge: 1000 * 60 * 60 * 24 * 7, + maxAge: 60 * 60 * 24 * 7, httpOnly: true, sameSite: 'strict', domain: 'example.com',