Using the React SDK
To log a user out, use thelogout method from the useMoonKey hook:
Basic Usage
With Async Handling
Sincelogout returns a Promise, you can await it to run code after the user has been logged out:
Common Patterns
Logout with Confirmation
Ask the user to confirm before logging out:Logout with Loading State
Show a loading state during logout:Logout in Header/Navigation
Common pattern for a header component:Logout with Redirect
Redirect to a specific page after logout:Dropdown Menu with Logout
Common pattern for user menus:Effect of Logout
When you calllogout(), MoonKey will:
- Clear the session - Remove session tokens and JWTs from IndexedDB
- Reset authentication state - Set
isAuthenticatedtofalse - Clear user data - Remove the user object from the SDK state
- Revoke session on server - Invalidate the session on MoonKey’s backend