From c8f6cb0b3469fbf0a80e7c5614497a388fc4b478 Mon Sep 17 00:00:00 2001 From: Rogee Date: Tue, 30 Dec 2025 22:14:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(auth):=20=E6=B7=BB=E5=8A=A0401=E6=9C=AA?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E5=A4=84=E7=90=86=EF=BC=8C=E6=B8=85=E9=99=A4?= =?UTF-8?q?token=E5=B9=B6=E9=87=8D=E5=AE=9A=E5=90=91=E5=88=B0=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/portal/src/utils/request.js | 10 ++++++++++ 1 file changed, 10 insertions(+) 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);