react-context-auth-user-switch
CommunityFix stale React auth data when switching users without reload.
System Documentation
What problem does it solve?
When using React Context paired with localStorage for authentication state, switching between user accounts within the same browser tab fails to update the user interface, leaving stale previous user data visible. This occurs because localStorage changes do not trigger React re-renders, and same-tab storage events do not fire to notify the app of data changes.
Core Features & Use Cases
- Explicit context refresh on login: Triggers an immediate update of React Context state right after a user logs in, before navigating to protected pages, eliminating stale data.
- Context reset on logout: Clears all stale user-related state from React Context when a user logs out, preventing leftover data from being visible to the next user.
- Polling fallback for edge cases: Includes a lightweight polling mechanism to catch user switches triggered by browser back/forward navigation, direct URL access after login, or page refreshes.
- Use case: Ideal for React single-page applications with multiple user account support, WhatsApp-style chatbots with per-user conversation lists, and apps with auth-protected routes that require immediate state updates on account switch.
Quick Start
Use the react-context-auth-user-switch skill to fix stale user data in your React single-page application when users switch accounts without reloading the page.
Dependency Matrix
Required Modules
None requiredComponents
Standard package💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: react-context-auth-user-switch Download link: https://github.com/freedomw1987/tree_monstor/archive/main.zip#react-context-auth-user-switch Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 537,000+ vetted skills library on demand.