浏览代码

修复 token过期且刷新成功任然自动退出系统,返回登录页的问题

zhontai 2 年之前
父节点
当前提交
661e819d61
共有 2 个文件被更改,包括 10 次插入4 次删除
  1. 5 2
      gen/templates/http-client.ejs
  2. 5 2
      src/api/admin/http-client.ts

+ 5 - 2
gen/templates/http-client.ejs

@@ -214,6 +214,7 @@ export class HttpClient<SecurityDataType = unknown> {
       }
 
       if (window.tokenRefreshing) {
+        window.requests = window.requests ? window.requests : []
         return new Promise((resolve) => {
           window.requests.push(() => {
             resolve(this.instance(config))
@@ -237,8 +238,10 @@ export class HttpClient<SecurityDataType = unknown> {
         if (res?.success) {
           const token = res.data.token
           setToken(token)
-          window.requests.forEach((apiRequest) => apiRequest())
-          window.requests = []
+          if (window.requests?.length > 0) {
+            window.requests.forEach((apiRequest) => apiRequest())
+            window.requests = []
+          }
           return this.instance(config)
         } else {
           clearToken()

+ 5 - 2
src/api/admin/http-client.ts

@@ -218,6 +218,7 @@ export class HttpClient<SecurityDataType = unknown> {
     }
 
     if (window.tokenRefreshing) {
+      window.requests = window.requests ? window.requests : []
       return new Promise((resolve) => {
         window.requests.push(() => {
           resolve(this.instance(config))
@@ -241,8 +242,10 @@ export class HttpClient<SecurityDataType = unknown> {
         if (res?.success) {
           const token = res.data.token
           setToken(token)
-          window.requests.forEach((apiRequest) => apiRequest())
-          window.requests = []
+          if (window.requests?.length > 0) {
+            window.requests.forEach((apiRequest) => apiRequest())
+            window.requests = []
+          }
           return this.instance(config)
         } else {
           clearToken()