Refactored UI endpoint usage
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import axios, { InternalAxiosRequestConfig } from 'axios';
|
||||
import { getApiBaseUrl } from '../config';
|
||||
import { triggerSessionExpired, isUserSyncEndpoint } from './sessionExpiration';
|
||||
import { isUserSyncedInBrowser, isActivationPending, syncUserAccount } from './userSyncService';
|
||||
|
||||
export const BASE_API_URL = getApiBaseUrl();
|
||||
|
||||
@@ -28,8 +29,6 @@ apiClient.interceptors.request.use(
|
||||
// All API calls require an authenticated and enabled user in the backend system.
|
||||
const isSyncRequest = isUserSyncEndpoint(config.url);
|
||||
if (token && !isSyncRequest) {
|
||||
const { isUserSyncedInBrowser, isActivationPending, syncUserAccount } = await import('./userSyncService');
|
||||
|
||||
// If user account is flagged as pending administrator activation, block downstream API calls
|
||||
if (isActivationPending()) {
|
||||
return Promise.reject(new Error('User account is pending administrator activation'));
|
||||
@@ -57,11 +56,9 @@ apiClient.interceptors.response.use(
|
||||
const requestUrl = error.config?.url;
|
||||
const isSyncEndpoint = isUserSyncEndpoint(requestUrl);
|
||||
|
||||
// Disambiguation between Session Lockout and Session Expired:
|
||||
// - Session Expired process monitors ALL OTHER endpoints for HTTP 401 other than the user sync endpoint.
|
||||
// - User sync endpoint 401 is subordinated to the session lockout / auth initialization flow through call order and priority.
|
||||
// Handle 401 Unauthorized errors
|
||||
if (!isSyncEndpoint) {
|
||||
// Active working endpoint returned HTTP 401: trigger modal with progress bar countdown and landing redirect
|
||||
// Working endpoint returned HTTP 401: trigger session expiration prompt
|
||||
const detailMsg =
|
||||
error?.response?.data?.detail ||
|
||||
error?.response?.data?.message ||
|
||||
@@ -69,7 +66,7 @@ apiClient.interceptors.response.use(
|
||||
|
||||
triggerSessionExpired(detailMsg, requestUrl);
|
||||
} else {
|
||||
// User sync endpoint returned HTTP 401: clean up session data silently for landing navigation
|
||||
// User sync endpoint returned HTTP 401: clear cached auth state
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.removeItem('pfm_access_token');
|
||||
localStorage.removeItem('pfm_access_user');
|
||||
|
||||
Reference in New Issue
Block a user