diff --git a/src/stores/login.ts b/src/stores/login.ts index 605f5ab..f1842d5 100644 --- a/src/stores/login.ts +++ b/src/stores/login.ts @@ -30,7 +30,6 @@ export const useLoginStore = defineStore('loginStore', { userData: {}, isLoggedIn: false, rememberedReturnToUrl: "", - expired: (() => { const d = new Date(); d.setMonth(d.getMonth() + 6); return d.getTime(); })(), // 設定 Refresh Token 的到期日為半年後 }), actions: { /** @@ -51,7 +50,9 @@ export const useLoginStore = defineStore('loginStore', { const refresh_token = response.data.refresh_token; // 將 token 儲存在 cookie setCookieWithoutExpiration("luciaToken", accessToken); - setCookie("luciaRefreshToken", refresh_token, Math.ceil((this.expired - Date.now()) / (24 * 60 * 60 * 1000))); + const expiryDate = new Date(); + expiryDate.setMonth(expiryDate.getMonth() + 6); + setCookie("luciaRefreshToken", refresh_token, Math.ceil((expiryDate.getTime() - Date.now()) / (24 * 60 * 60 * 1000))); this.isLoggedIn = true; setCookie("isLuciaLoggedIn", "true"); diff --git a/tests/stores/login.test.js b/tests/stores/login.test.js index e282103..d3357eb 100644 --- a/tests/stores/login.test.js +++ b/tests/stores/login.test.js @@ -249,16 +249,4 @@ describe('loginStore', () => { }); }); - describe('expired', () => { - it('is approximately 6 months in the future', () => { - const now = new Date(); - const sixMonthsLater = new Date(now); - sixMonthsLater.setMonth(sixMonthsLater.getMonth() + 6); - - const expiredDate = new Date(store.expired); - // Allow 1 day tolerance - const diffMs = Math.abs(expiredDate.getTime() - sixMonthsLater.getTime()); - expect(diffMs).toBeLessThan(24 * 60 * 60 * 1000); - }); - }); });