AuthContext.tsx
[Isolated Context View]
// VULNERABLE: State mutations are entirely bound to the local runtime memory thread.
// If Tab A updates its storage, Tab B has no idea and becomes a zombie session.
export const AuthProvider = ({ children }: { children: ReactNode }) => {
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(!!localStorage.getItem('token'));
const [user, setUser] = useState<{ name: string } | null>(null);
const logout = () => {
localStorage.removeItem('token');
setIsAuthenticated(false);
setUser(null);
};
return (
<AuthContext.Provider value={{ isAuthenticated, logout, user }}>
{children}
</AuthContext.Provider>
);
};