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() {