token刷新问题
parent
6e04a5d3da
commit
f90807ebc6
3
App.vue
3
App.vue
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
/**
|
/**
|
||||||
* vuex管理登录状态,具体可以参考官方登录模板示例
|
* vuex管理登录状态,具体可以参考官方登录模板示例
|
||||||
|
@ -8,6 +6,7 @@ import { mapMutations } from "vuex";
|
||||||
import APPUpdate from "@/plugins/APPUpdate";
|
import APPUpdate from "@/plugins/APPUpdate";
|
||||||
import { getClipboardData } from "@/js_sdk/h5-copy/h5-copy.js";
|
import { getClipboardData } from "@/js_sdk/h5-copy/h5-copy.js";
|
||||||
import config from "@/config/config";
|
import config from "@/config/config";
|
||||||
|
import storage from "@/utils/storage.js";
|
||||||
// 悬浮球
|
// 悬浮球
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -119,9 +119,11 @@ http.interceptors.response.use(
|
||||||
response.data.status === 403
|
response.data.status === 403
|
||||||
) {
|
) {
|
||||||
if (!isRefreshing) {
|
if (!isRefreshing) {
|
||||||
|
console.log('旧token',token)
|
||||||
isRefreshing = true;
|
isRefreshing = true;
|
||||||
|
let oldRefreshToken = storage.getRefreshToken();
|
||||||
//调用刷新token的接口
|
//调用刷新token的接口
|
||||||
return refreshTokenFn(storage.getRefreshToken())
|
return refreshTokenFn(oldRefreshToken)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
let { accessToken, refreshToken } = res.data.result;
|
let { accessToken, refreshToken } = res.data.result;
|
||||||
storage.setAccessToken(accessToken);
|
storage.setAccessToken(accessToken);
|
||||||
|
@ -129,11 +131,13 @@ http.interceptors.response.use(
|
||||||
|
|
||||||
response.header.accessToken = `${accessToken}`;
|
response.header.accessToken = `${accessToken}`;
|
||||||
// token 刷新后将数组的方法重新执行
|
// token 刷新后将数组的方法重新执行
|
||||||
|
console.log('接口队列',requests,'新token',accessToken)
|
||||||
requests.forEach((cb) => cb(accessToken));
|
requests.forEach((cb) => cb(accessToken));
|
||||||
requests = []; // 重新请求完清空
|
requests = []; // 重新请求完清空
|
||||||
return http.request(response.config);
|
return http.request(response.config);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
console.log('刷新token报错'+oldRefreshToken,err)
|
||||||
cleanStorage();
|
cleanStorage();
|
||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
})
|
})
|
||||||
|
@ -153,9 +157,10 @@ http.interceptors.response.use(
|
||||||
|
|
||||||
// 如果当前返回没登录
|
// 如果当前返回没登录
|
||||||
} else if (
|
} else if (
|
||||||
(!token && response.statusCode === 403) ||
|
(!token && !storage.getRefreshToken() && response.statusCode === 403) ||
|
||||||
response.data.code === 403
|
response.data.code === 403
|
||||||
) {
|
) {
|
||||||
|
console.log('没有token 以及刷新token 内容',token,storage.getRefreshToken())
|
||||||
cleanStorage();
|
cleanStorage();
|
||||||
|
|
||||||
// 如果当前状态码为正常但是success为不正常时
|
// 如果当前状态码为正常但是success为不正常时
|
||||||
|
|
Loading…
Reference in New Issue