refactor: Address technical debt in auth refresh implementation

This commit is contained in:
Yunxiao Xu
2026-02-18 14:36:10 -08:00
parent 341bd08176
commit 6131f27142
4 changed files with 49 additions and 25 deletions

View File

@@ -69,22 +69,27 @@ api.interceptors.response.use(
console.error("Reactive refresh failed:", refreshError)
// Final failure - session is dead
if (onUnauthorized) {
onUnauthorized()
}
handleUnauthorized()
return Promise.reject(refreshError)
}
}
// If it's the refresh endpoint itself failing with 401, trigger logout
if (error.response?.status === 401 && isRefreshEndpoint) {
if (onUnauthorized) {
onUnauthorized()
}
// If it's a 401 on an endpoint we don't/can't refresh (like refresh itself or login)
if (error.response?.status === 401) {
handleUnauthorized()
}
return Promise.reject(error)
}
)
/**
* Shared helper to trigger logout/unauthorized cleanup.
*/
function handleUnauthorized() {
if (onUnauthorized) {
onUnauthorized()
}
}
export default api