前端热更新
This commit is contained in:
1 parent
af88732a07
commit
5b95fe8f40
3 files changed
+19
-16
No files matched your search
+11
-4
@@ -8,6 +8,13 @@ import {
|
||||
refreshIfNeeded,
|
||||
} from '../auth/session'
|
||||
|
||||
declare module 'axios' {
|
||||
export interface AxiosRequestConfig {
|
||||
// Public kiosk pages must remain usable when this browser has an expired login session.
|
||||
skipAuthSession?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
const http = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL ?? '/api',
|
||||
timeout: 15000,
|
||||
@@ -20,12 +27,12 @@ http.interceptors.request.use(async (config) => {
|
||||
config.url?.endsWith('/auth/logout') ||
|
||||
config.url?.endsWith('/auth/sso/exchange') ||
|
||||
config.url?.endsWith('/auth/sso/bind')
|
||||
if (!isAuthenticationRequest) {
|
||||
if (!isAuthenticationRequest && !config.skipAuthSession) {
|
||||
const activeToken = await refreshIfNeeded(true)
|
||||
if (activeToken) markActivity()
|
||||
}
|
||||
const token = localStorage.getItem(authStorageKeys.token)
|
||||
if (token) config.headers.Authorization = `Bearer ${token}`
|
||||
if (token && !config.skipAuthSession) config.headers.Authorization = `Bearer ${token}`
|
||||
return config
|
||||
})
|
||||
|
||||
@@ -40,7 +47,7 @@ http.interceptors.response.use(
|
||||
error.config?.url?.endsWith('/auth/sso/bind')
|
||||
const retryableConfig = error.config as
|
||||
(typeof error.config & { _jiaowuRetried?: boolean }) | undefined
|
||||
if (error.response?.status === 401 && !isAuthenticationRequest &&
|
||||
if (error.response?.status === 401 && !isAuthenticationRequest && !error.config?.skipAuthSession &&
|
||||
!retryableConfig?._jiaowuRetried) {
|
||||
const token = await refreshAuthSession()
|
||||
if (token && retryableConfig) {
|
||||
@@ -49,7 +56,7 @@ http.interceptors.response.use(
|
||||
return http.request(retryableConfig)
|
||||
}
|
||||
}
|
||||
if (error.response?.status === 401 && !isAuthenticationRequest) {
|
||||
if (error.response?.status === 401 && !isAuthenticationRequest && !error.config?.skipAuthSession) {
|
||||
clearAuthSession()
|
||||
goLogin(location.pathname + location.search + location.hash)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user