kabbouchi/nova-impersonate
kabbouchi/nova-impersonate adds one-click user impersonation to Laravel Nova. Admins can log in as any user directly from Nova, troubleshoot issues, and safely return to their own account. Ideal for support and debugging workflows.
Install the package into the Nova app and confirm Nova’s package discovery picks it up:
composer require kabbouchi/nova-impersonate
Add the field to the Nova resource that represents your authenticatable users, usually app/Nova/User.php:
use Kabbouchi\NovaImpersonate\Impersonate;
public function fields(NovaRequest $request)
{
return [
ID::make()->sortable(),
// ...
Impersonate::make()
->onlyOnDetail()
->canSee(fn (NovaRequest $request) => $request->user()->isAdmin()),
];
}
Look first at:
src/Impersonate.php for the field API and available meta/options.The first practical use case is support/debugging: an admin opens a user’s Nova detail page, clicks Impersonate, reproduces the user’s issue in the application, then uses the package’s leave route to return to their admin account. Test this in staging with a non-admin user before enabling it in production.
Use impersonation as a privileged support workflow, not as a general-purpose login shortcut.
canSee only hides UI; the route still needs protection.// app/Nova/User.php
Impersonate::make('Login as user')
->onlyOnDetail()
->canSee(fn (NovaRequest $request) =>
$request->user()->can('impersonate', $this->resource)
),
// app/Policies/UserPolicy.php
public function impersonate(User $user, User $target): bool
{
return $user->isAdmin()
&& ! $target->isAdmin()
&& $user->isNot($target);
}
If your app uses a non-default auth guard, keep the Nova guard and impersonation guard aligned. The exact API depends on the installed version; check the field class/README, but it is commonly configured through field meta or package config:
Impersonate::make()
->withMeta(['guard' => 'web']);
Provide an obvious “stop impersonating” path outside Nova. If the package exposes a leave route, wire it into your app layout:
@impersonating
<form method="POST" action="{{ route('impersonate.leave') }}">
@csrf
<button type="submit">Return to admin</button>
</form>
@endimpersonating
Add an audit trail around the workflow: record the original admin ID, target user ID, timestamp, IP, and user agent. If the package does not emit events in your version, log inside middleware around the impersonation route or in your own thin controller wrapper.
For tests, exercise the route rather than only the field:
$this->actingAs($admin)
->post(route('nova-impersonate.start', $user))
->assertRedirect();
$this->assertAuthenticatedAs($user);
Use the package route name from the installed version; inspect php artisan route:list | grep -i impersonate.
web, while your app uses an admin guard or custom provider. Impersonating across guards can log the admin out, produce a 403, or authenticate against the wrong model.canSee alone.src/, routes/, and the published JS/assets.How can I help you explore Laravel packages today?