diff --git a/frontend/portal/src/utils/request.js b/frontend/portal/src/utils/request.js index 9d6178b..c2e9a63 100644 --- a/frontend/portal/src/utils/request.js +++ b/frontend/portal/src/utils/request.js @@ -36,6 +36,16 @@ export async function request(endpoint, options = {}) { } if (!res.ok) { + // Handle 401 Unauthorized + if (res.status === 401) { + localStorage.removeItem('token'); + localStorage.removeItem('user'); + // Redirect to login if not already there + if (!window.location.pathname.startsWith('/auth/login')) { + window.location.href = '/auth/login'; + } + } + // Handle errorx response { code, message, error_id } const errorMsg = data.message || `Request failed with status ${res.status}`; throw new Error(errorMsg);