From 37372666a42f88729c1315af6cacdcc0ea5355be Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Wed, 19 Feb 2025 15:18:34 +0700 Subject: [PATCH] fix cookie --- src/plugins/auth.ts | 20 +++++++++++++++++++- src/views/login.vue | 4 ++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/plugins/auth.ts b/src/plugins/auth.ts index 0753a6e..9928fab 100644 --- a/src/plugins/auth.ts +++ b/src/plugins/auth.ts @@ -16,6 +16,11 @@ async function setAuthen(r: AuthResponse) { window.location.href = '/' } +async function setAuthenCheckin(r: AuthResponse) { + await setCookieCheckin(ACCESS_TOKEN, r.access_token, r.expires_in) + window.location.href = '/' +} + async function logout() { await deleteCookie(ACCESS_TOKEN) window.location.href = key_C_Config.url_Logout @@ -31,6 +36,19 @@ function setCookie(name: string, value: any, time: number) { const date = new Date() date.setTime(date.getTime() + time * 1000) // date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); + date.setMonth(date.getMonth() + 6) + expires = '; expires=' + date.toUTCString() + } + document.cookie = name + '=' + (value || '') + expires + '; path=/' +} + +function setCookieCheckin(name: string, value: any, time: number) { + let expires = '' + if (time) { + const date = new Date() + + // date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); + date.setMonth(date.getMonth() + 6) expires = '; expires=' + date.toUTCString() } document.cookie = name + '=' + (value || '') + expires + '; path=/' @@ -71,4 +89,4 @@ async function tokenParsed() { return JSON.parse(jsonPayload) } -export { getToken, authenticated, logout, setAuthen, tokenParsed } +export { getToken, authenticated, logout, setAuthen, tokenParsed ,setAuthenCheckin} diff --git a/src/views/login.vue b/src/views/login.vue index 127c837..80293ff 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -5,7 +5,7 @@ import axios from 'axios' import { useRouter } from 'vue-router' import { useQuasar } from 'quasar' import { useCounterMixin } from '@/stores/mixin' -import { setAuthen, authenticated } from '@/plugins/auth' +import { setAuthen, authenticated, setAuthenCheckin } from '@/plugins/auth' import CustomComponent from '@/components/CustomDialog.vue' import env from '@/api/index' @@ -30,7 +30,7 @@ async function onSubmit() { }, }) .then(async (res) => { - setAuthen(res.data.result) + setAuthenCheckin(res.data.result) }) .catch((err) => { $q.dialog({