fix: auto-redirect to login on 401 Unauthorized
When API returns 401, clear stored tokens and redirect to /login instead of showing an error message. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
375c5632f6
commit
d21f41d7c3
|
|
@ -42,6 +42,13 @@ export async function apiClient<T>(endpoint: string, options: RequestOptions = {
|
|||
});
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 401 && typeof window !== 'undefined') {
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('refresh_token');
|
||||
localStorage.removeItem('current_tenant');
|
||||
window.location.href = '/login';
|
||||
throw new Error('Session expired');
|
||||
}
|
||||
const errorData = await response.json().catch(() => null);
|
||||
const message = errorData?.message || `${response.status} ${response.statusText}`;
|
||||
throw new Error(message);
|
||||
|
|
|
|||
Loading…
Reference in New Issue