From 05ef481f0a610fad2afe15016ca5dcc2ea04cac3 Mon Sep 17 00:00:00 2001 From: ivamp Date: Sat, 17 Aug 2024 17:30:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E7=9A=84=20token=20=E5=88=B0=E6=9C=9F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/user.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/stores/user.ts b/src/stores/user.ts index 08360e9..42e72b8 100644 --- a/src/stores/user.ts +++ b/src/stores/user.ts @@ -41,20 +41,17 @@ export const useUserStore = defineStore("user", { this.user.id = idTokenPayload.sub; this.logined = true; }, - setupTimer() { - timer = setInterval(() => { - if (this.logined) { - if (this.expired_at - Date.now() < 60000) { - this.refresh(); - } else { - // 显示还有多长时间过期 - // console.log( - // "Token will expire in " + - // (this.expired_at - Date.now()) / 1000 + - // " seconds" - // ); - } + checkAndRefresh() { + if (this.logined) { + if (this.expired_at - Date.now() < 60000) { + this.refresh(); } + } + }, + setupTimer() { + this.checkAndRefresh(); + timer = setInterval(() => { + this.checkAndRefresh(); }, 10 * 1000); }, async refresh() {