abdullyahuza / filament-impersonate
Filament Impersonate allows administrators to securely impersonate other users within the Filament admin panel. With a simple "Impersonate" action, admins can log in as another user to troubleshoot issues, test permissions, or preview user-specific content. A visible banner indicates impersonation m
Requires
- php: ^8.1
- filament/filament: ^3.0
- spatie/laravel-permission: ^6.0
README
๐ญ Filament Impersonate
A plugin for Filament Admin Panel that allows authorized users to impersonate other users.
๐ฆ Installation
composer require abdullyahuza/filament-impersonate
Optionally publish the config file:
php artisan vendor:publish --tag="filament-impersonate-config"
โ๏ธ Configuration
Inside config/filament-impersonate.php
:
return [ 'redirect_after_impersonation' => 'filament.app.pages.dashboard', 'guard' => 'web', 'user_model' => \App\Models\User::class, 'session_key' => 'filament_impersonator_id', 'excluded_user_ids' => [/* user IDs that should never be impersonated */], 'allowed_environments' => ['local', 'staging', 'production'], 'display_name_resolver' => fn ($user) => $user->name ?? 'Unknown User', 'can_impersonate_resolver' => fn ($user) => $user?->hasRole('admin') || $user?->can('impersonate users'), ];
Setup Filament-Impersonate
Install for Panel
->plugins([
...
FilamentImpersonate::make(),
])
->middleware([
...
// AuthenticateSession::class,
])
โ Usage
Impersonate a user
- From the Filament UI, click the impersonation button shown next to user profile (if allowed).
- You will be logged in as that user.
- A banner or button will appear indicating impersonation โ click it to stop impersonating.
Stop impersonating
Click the "Stop Impersonating" button to return to your original user session.
๐ Permissions
To restrict who can impersonate users, configure the can_impersonate_resolver
in your config file.
Example:
'can_impersonate_resolver' => fn ($user) => $user?->hasRole('admin') || $user?->can('impersonate_users'),
๐พ Session Management
During impersonation, the following is stored in the session:
- Impersonator ID
- Original user roles & permissions (if applicable)
These are restored when impersonation is stopped.
๐ก๏ธ Notes
- Only users not in
excluded_user_ids
can be impersonated. - Impersonation only works in environments defined in
allowed_environments
. - You can customize how user names are displayed using
display_name_resolver
.
๐งช Testing
Ensure your environment is included in allowed_environments
for local testing.
'allowed_environments' => ['local'],
๐ License
The MIT License (MIT). Please see License File for more information.