fix: 仅主 API 的 401 清除登录态,避免模块服务误登出
This commit is contained in:
@@ -23,7 +23,6 @@ export const useMpStore = defineStore({
|
||||
async fetchMpInfo() {
|
||||
const info = await getMpInfo().catch((err => {
|
||||
console.log(err.code,'fetchMpInfo()')
|
||||
uni.clearStorageSync()
|
||||
}));
|
||||
if (!info) {
|
||||
return {};
|
||||
|
||||
+11
-3
@@ -5,6 +5,14 @@ import {
|
||||
} from '@/config/setting';
|
||||
|
||||
const http = new Request();
|
||||
|
||||
// 只有主 API(core) 的 401 才代表登录态失效;shop/booking 等独立服务有自己的令牌体系
|
||||
function isCoreRequest(url?: string) {
|
||||
if (!url) {
|
||||
return true;
|
||||
}
|
||||
return url.startsWith(SERVER_API_URL) || url.startsWith('/');
|
||||
}
|
||||
/**
|
||||
* @description 修改全局默认配置
|
||||
* @param {Function}
|
||||
@@ -48,8 +56,8 @@ http.interceptors.response.use((response) => {
|
||||
// return response.data
|
||||
// }
|
||||
|
||||
// token过期
|
||||
if (response.data.code == 401) {
|
||||
// token过期(仅主 API)
|
||||
if (response.data.code == 401 && isCoreRequest(response.config.url)) {
|
||||
uni.removeStorageSync('access_token')
|
||||
uni.removeStorageSync('user_id')
|
||||
uni.removeStorageSync('phone')
|
||||
@@ -57,7 +65,7 @@ http.interceptors.response.use((response) => {
|
||||
if (response.data.code == 1) {
|
||||
return Promise.reject(response.data)
|
||||
}
|
||||
if (response.data.message === '请先登录') {
|
||||
if (response.data.message === '请先登录' && isCoreRequest(response.config.url)) {
|
||||
uni.removeStorageSync('access_token')
|
||||
uni.removeStorageSync('user_id')
|
||||
uni.removeStorageSync('phone')
|
||||
|
||||
Reference in New Issue
Block a user