feat(http): enhance request authorization handling for login requests
Frontend CI / Frontend (push) Successful in 1m53s
Frontend CI / Frontend (push) Successful in 1m53s
fix(login-view): improve error message formatting for login errors
This commit is contained in:
@@ -43,9 +43,15 @@ const client: AxiosInstance = axios.create({
|
||||
timeout: 30000,
|
||||
})
|
||||
|
||||
function isLoginRequest(url: string | undefined, method: string | undefined): boolean {
|
||||
return (
|
||||
method?.toLowerCase() === 'post' && (url === '/auth/login' || Boolean(url?.endsWith('/auth/login')))
|
||||
)
|
||||
}
|
||||
|
||||
client.interceptors.request.use((config) => {
|
||||
const { session } = readStoredSession()
|
||||
if (session.accessToken) {
|
||||
if (session.accessToken && !isLoginRequest(config.url, config.method)) {
|
||||
config.headers = config.headers ?? {}
|
||||
config.headers['Authorization'] = `Bearer ${session.accessToken}`
|
||||
}
|
||||
@@ -58,7 +64,7 @@ client.interceptors.response.use(
|
||||
const status = error.response?.status
|
||||
const payload = error.response?.data
|
||||
|
||||
if (status === 401) {
|
||||
if (status === 401 && !isLoginRequest(error.config?.url, error.config?.method)) {
|
||||
clearStoredSession()
|
||||
onUnauthorized?.()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user