From b5987f2e8dd10ef524866e0abeb083bda4402d20 Mon Sep 17 00:00:00 2001 From: Cheng Gu Date: Thu, 10 Aug 2023 10:48:39 +0800 Subject: [PATCH] feat: set cookies' expires attribute and fix remember me (#530) --- frontend/composables/use-auth-context.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frontend/composables/use-auth-context.ts b/frontend/composables/use-auth-context.ts index a8fedc0..e366101 100644 --- a/frontend/composables/use-auth-context.ts +++ b/frontend/composables/use-auth-context.ts @@ -114,6 +114,16 @@ class AuthContext implements IAuthContext { const r = await api.login(email, password, stayLoggedIn); if (!r.error) { + const expiresAt = new Date(r.data.expiresAt); + this._token = useCookie(AuthContext.cookieTokenKey, { + expires: expiresAt, + }); + this._expiresAt = useCookie(AuthContext.cookieExpiresAtKey, { + expires: expiresAt, + }); + this._attachmentToken = useCookie(AuthContext.cookieAttachmentTokenKey, { + expires: expiresAt, + }); this._token.value = r.data.token; this._expiresAt.value = r.data.expiresAt as string; this._attachmentToken.value = r.data.attachmentToken;