Impersonation is a client-side React component that displays a banner when an administrator is impersonating a user. It shows the impersonated user’s details and provides a button to stop the impersonation.
Usage
Props
Position of the impersonation banner on the screen.
URL to redirect to after stopping impersonation. If not provided, the user will be redirected to the default location.
All standard HTML div attributes are supported and will be passed to the root element.
Styling
The component supports CSS custom properties for customization:Example: Custom styling
Behavior
Automatic display
Automatic display
The component automatically renders when the current user is being impersonated. It remains hidden when no impersonation is active.
Organization context
Organization context
If the impersonated user is in an organization, the banner displays both the user’s email and the organization name.
Minimize/maximize
Minimize/maximize
The banner includes a toggle button to minimize it to a small indicator, reducing visual clutter while maintaining awareness of the impersonation state.
Stop impersonation
Stop impersonation
Clicking the Stop button ends the impersonation session and signs out the impersonated user, returning to the admin’s session.
Implementation details
The component:- Uses
useAuth()to access impersonation state - Fetches organization details when the user is in an organization context
- Renders nothing when not impersonating
- Creates a fixed-position overlay with a minimizable form
- Handles sign-out with optional redirect
Example with both positions
Accessibility
The component is built with semantic HTML and includes:- Proper form structure for the stop button
- Clear visual indicators of impersonation state
- Keyboard-accessible controls
Related
useAuth
Access impersonation state
Impersonation guide
Learn about user impersonation