diff --git a/src/lib/core.ts b/src/lib/core.ts index 20bfca0..842f66c 100644 --- a/src/lib/core.ts +++ b/src/lib/core.ts @@ -86,7 +86,7 @@ export class CookieSession> { let maxAge = this.#config.cookie.maxAge; if (this.#sessionData?.expires) { - maxAge = new Date(this.#sessionData.expires).getTime() / 1000 - new Date().getTime() / 1000; + maxAge = Math.round(new Date(this.#sessionData.expires).getTime() / 1000 - new Date().getTime() / 1000); } this.#state.needsSync = true; @@ -143,7 +143,7 @@ export class CookieSession> { let maxAge = this.#config.cookie.maxAge; if (this.#sessionData?.expires) { - maxAge = new Date(this.#sessionData.expires).getTime() / 1000 - new Date().getTime() / 1000; + maxAge = Math.round(new Date(this.#sessionData.expires).getTime() / 1000 - new Date().getTime() / 1000); } await this.setCookie(maxAge); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c7bd0a9..3dd11d9 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -5,11 +5,11 @@ import type { MaybePromise } from '@sveltejs/kit'; export function expiresToMaxage(expires: number, expires_in: 'days' | 'hours' | 'minutes' | 'seconds') { switch (expires_in) { case 'days': - return expires * 24 * 60 * 60; + return Math.round(expires * 24 * 60 * 60); case 'hours': - return expires * 60 * 60; + return Math.round(expires * 60 * 60); case 'minutes': - return expires * 60; + return Math.round(expires * 60); case 'seconds': return expires; default: