danylokhodus commited on
Commit
e99b444
·
1 Parent(s): 6f4307f

fix(auth): automatically logout if profile fetch returns 404

Browse files
Files changed (1) hide show
  1. src/context/AuthContext.jsx +2 -2
src/context/AuthContext.jsx CHANGED
@@ -26,8 +26,8 @@ export const AuthProvider = ({ children }) => {
26
  } catch (error) {
27
  console.error('[Auth] Failed to fetch profile:', error);
28
  // Only logout on explicit authorization failures (e.g. 401, 403). Keep session on server network errors.
29
- if (error.response && (error.response.status === 401 || error.response.status === 403)) {
30
- console.warn('[Auth] Token is expired or invalid. Logging out.');
31
  logout();
32
  } else {
33
  console.warn('[Auth] Server is unreachable or returned network error. Retaining session.');
 
26
  } catch (error) {
27
  console.error('[Auth] Failed to fetch profile:', error);
28
  // Only logout on explicit authorization failures (e.g. 401, 403). Keep session on server network errors.
29
+ if (error.response && (error.response.status === 401 || error.response.status === 403 || error.response.status === 404)) {
30
+ console.warn('[Auth] Token is expired, invalid, or user was not found on server. Logging out.');
31
  logout();
32
  } else {
33
  console.warn('[Auth] Server is unreachable or returned network error. Retaining session.');