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

v1.0.0 2025-07-21 10:47 UTC

This package is auto-updated.

Last update: 2025-07-21 14:08:27 UTC


README

DEMO UI

๐ŸŽญ Filament Impersonate

License: MIT

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

  1. From the Filament UI, click the impersonation button shown next to user profile (if allowed).
  2. You will be logged in as that user.
  3. 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.