fix(projects): 修复切换用户或登录过期部分问题
This commit is contained in:
parent
72b8f56e32
commit
27f061957e
@ -1,3 +1,4 @@
|
||||
import { useRoute } from 'vue-router';
|
||||
import type { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
||||
import { BACKEND_ERROR_CODE, REQUEST_CANCELED_CODE, createFlatRequest } from '@sa/axios';
|
||||
import { useAuthStore } from '@/store/modules/auth';
|
||||
@ -51,6 +52,7 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
|
||||
return String(response.data.code) === import.meta.env.VITE_SERVICE_SUCCESS_CODE;
|
||||
},
|
||||
async onBackendFail(response, instance) {
|
||||
const route = useRoute();
|
||||
const authStore = useAuthStore();
|
||||
const responseCode = String(response.data.code);
|
||||
|
||||
@ -66,6 +68,10 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
|
||||
}
|
||||
|
||||
// when the backend response code is in `logoutCodes`, it means the user will be logged out and redirected to login page
|
||||
if (route.name === 'login') {
|
||||
handleLogout();
|
||||
return null;
|
||||
}
|
||||
// const logoutCodes = import.meta.env.VITE_SERVICE_LOGOUT_CODES?.split(',') || [];
|
||||
// if (logoutCodes.includes(responseCode)) {
|
||||
// handleLogout();
|
||||
|
@ -61,6 +61,7 @@ const callbackByCode = async (data: Api.Auth.SocialLoginForm) => {
|
||||
|
||||
const loginByCode = async (data: Api.Auth.SocialLoginForm) => {
|
||||
try {
|
||||
await authStore.logout();
|
||||
await authStore.login(data);
|
||||
await processResponse();
|
||||
} catch {
|
||||
|
Loading…
Reference in New Issue
Block a user