🐛 Bug: Multi-tenant Logout State Not Properly Cleared
Description
When a user logs into Company A, switches to Company B, logs out from Company B, and then uses the browser's back button, the user from Company A still appears logged in.
Steps to Reproduce
- Log in to Company A
- Switch to Company B
- Log out from Company B
- Click browser back button
- Observe: Company A's account still shows as logged in
Root Cause Analysis
Code Location:
frontend/src/stores/index.ts - logout function
frontend/src/App.tsx - App initialization logic
Issue 1: Incomplete Logout Cleanup
The current logout function only clears token and user, but doesn't clear other authentication-related data:
logout: () => {
localStorage.removeItem('token');
set({ user: null, token: null });
},
Issue 2: Browser Back Cache State
When using browser back button, the page may restore from cache without full re-initialization. The App.tsx initialization logic may not properly re-validate the user state:
if (effectiveToken && !user) {
authApi.me()
.then((u) => setAuth(u, effectiveToken!))
.catch(() => useAuthStore.getState().logout())
.finally(() => setLoading(false));
}
Suggested Fix
Option 1: Enhanced Logout Function
logout: () => {
localStorage.removeItem('token');
localStorage.removeItem('user');
localStorage.removeItem('current_tenant_id');
sessionStorage.clear();
set({ user: null, token: null });
},
Option 2: Add Validation in App Initialization
Verify that the returned user context matches the expected tenant before restoring session.
Labels
- bug
- multi-tenant
- security
🐛 Bug: Multi-tenant Logout State Not Properly Cleared
Description
When a user logs into Company A, switches to Company B, logs out from Company B, and then uses the browser's back button, the user from Company A still appears logged in.
Steps to Reproduce
Root Cause Analysis
Code Location:
frontend/src/stores/index.ts-logoutfunctionfrontend/src/App.tsx- App initialization logicIssue 1: Incomplete Logout Cleanup
The current
logoutfunction only clearstokenanduser, but doesn't clear other authentication-related data:Issue 2: Browser Back Cache State
When using browser back button, the page may restore from cache without full re-initialization. The App.tsx initialization logic may not properly re-validate the user state:
Suggested Fix
Option 1: Enhanced Logout Function
Option 2: Add Validation in App Initialization
Verify that the returned user context matches the expected tenant before restoring session.
Labels