From 415d38381f942a4e454262e29e3a8b5c642aa854 Mon Sep 17 00:00:00 2001 From: rishab-endcloud Date: Tue, 25 Nov 2025 00:59:42 +0530 Subject: [PATCH] awrawr --- src/services/authService.jsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/services/authService.jsx b/src/services/authService.jsx index af844a6..d012e30 100644 --- a/src/services/authService.jsx +++ b/src/services/authService.jsx @@ -11,13 +11,15 @@ class AuthService { withCredentials: true // Enable sending cookies with requests }); + this.isLoggingOut = false; // Handle authentication errors (401/403) but don't auto-redirect on network errors this.api.interceptors.response.use( (response) => response, (error) => { // Only auto-logout on explicit authentication errors, not network issues - if (error.response && (error.response.status === 401 || error.response.status === 403)) { + // and prevent infinite loops + if (error.response && (error.response.status === 401 || error.response.status === 403) && !this.isLoggingOut) { this.logout(); // Only redirect if not already on auth page to avoid redirect loops if (window.location.pathname !== '/auth') { @@ -65,11 +67,21 @@ class AuthService { } async logout() { + if (this.isLoggingOut) { + return; // Prevent multiple logout calls + } + + this.isLoggingOut = true; + try { await this.api.post('/auth/logout'); // Cookies are cleared by backend; no local storage to clear since we avoid storing tokens in dev. } catch (error) { console.error('Logout API call failed:', error); + } finally { + this.isLoggingOut = false; + // Clear in-memory tokens + this.clearToken(); } }