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 type { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
||||||
import { BACKEND_ERROR_CODE, REQUEST_CANCELED_CODE, createFlatRequest } from '@sa/axios';
|
import { BACKEND_ERROR_CODE, REQUEST_CANCELED_CODE, createFlatRequest } from '@sa/axios';
|
||||||
import { useAuthStore } from '@/store/modules/auth';
|
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;
|
return String(response.data.code) === import.meta.env.VITE_SERVICE_SUCCESS_CODE;
|
||||||
},
|
},
|
||||||
async onBackendFail(response, instance) {
|
async onBackendFail(response, instance) {
|
||||||
|
const route = useRoute();
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
const responseCode = String(response.data.code);
|
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
|
// 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(',') || [];
|
// const logoutCodes = import.meta.env.VITE_SERVICE_LOGOUT_CODES?.split(',') || [];
|
||||||
// if (logoutCodes.includes(responseCode)) {
|
// if (logoutCodes.includes(responseCode)) {
|
||||||
// handleLogout();
|
// handleLogout();
|
||||||
|
@ -61,6 +61,7 @@ const callbackByCode = async (data: Api.Auth.SocialLoginForm) => {
|
|||||||
|
|
||||||
const loginByCode = async (data: Api.Auth.SocialLoginForm) => {
|
const loginByCode = async (data: Api.Auth.SocialLoginForm) => {
|
||||||
try {
|
try {
|
||||||
|
await authStore.logout();
|
||||||
await authStore.login(data);
|
await authStore.login(data);
|
||||||
await processResponse();
|
await processResponse();
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user