dutchcodingcompany/filament-developer-logins

Add buttons to the login page of Filament to login as a specific user.

1.1.0 2024-05-03 11:18 UTC

This package is auto-updated.

Last update: 2024-05-03 13:36:09 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This plugin allows you to enable one-click logins for your local Filament panels, which is useful when developing a Filament project with multiple users and various roles.

example-screenshot.png

Installation

You can install the package via composer.

composer require dutchcodingcompany/filament-developer-logins

Usage

Register the plugin in the Filament panel provider (the default file is app/Providers/Filament/AdminPanelProvider.php).

In the users method you can define the users (note: the users must exist), the key is used as a label on the login button and the value is used to search the user in the database.

// ...
->plugins([
    FilamentDeveloperLoginsPlugin::make()
        ->enabled()
        ->users([
            'Admin' => 'admin@dutchcodingcompany.com',
            'User' => 'user@dutchcodingcompany.com',
        ])
]);

Customization

enabled()

By default, the plugin is disabled. You can enable it by calling the enabled() method. I strongly suggest enabling this plugin only in the local environment. You can achieve this by using the app()->environment() method. Additionally, the enabled() method also accepts a closure if you wish to enable the plugin based on a custom condition.

Example:

// ...
FilamentDeveloperLoginsPlugin::make()
    ->enabled(app()->environment('local'))

switchable()

By default, a "Switch to" button is shown in the top right corner of the screen, so you can easily switch between the provided users. If you want to disable this feature, you can use the switchable() method.

// ...
FilamentDeveloperLoginsPlugin::make()
    ->switchable(false) // This also accepts a closure.

example-screenshot.png

column()

By default, the user column is set to email. If you want to use a different column, you can use the column() method.

Example:

FilamentDeveloperLoginsPlugin::make()
    ->column('name')

modelClass()

By default, the model class is set to App\Models\User. If you want to use a different model, you can use the modelClass() method.

Example:

FilamentDeveloperLoginsPlugin::make()
    ->modelClass(Admin::class)

RedirectTo()

By default, the user will be redirected using the Filament::getUrl() method, which directs them to the dashboard. In the case of multi-tenancy, the user will also be redirected to the correct tenant. If you prefer to use a different route, you can utilize the redirectTo() method.

FilamentDeveloperLoginsPlugin::make()
    ->redirectTo('/custom-route')

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.