Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Developer Logins Laravel Package

dutchcodingcompany/filament-developer-logins

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install via Composer:
    composer require dutchcodingcompany/filament-developer-logins
    
  2. Publish the config (optional, but recommended for customization):
    php artisan vendor:publish --provider="DutchCodingCompany\FilamentDeveloperLogins\FilamentDeveloperLoginsServiceProvider"
    
  3. Add to your Filament panel: In your PanelProvider (e.g., app/Providers/Filament/AdminPanelProvider.php), register the plugin:
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugin(FilamentDeveloperLoginsPlugin::make());
    }
    

First Use Case

  • Quick User Switching: During local development, log in as different users (e.g., admin, editor, customer) without manually resetting passwords or using php artisan filament:login.
  • Demo Environments: Share a demo link with stakeholders where they can log in as predefined users (e.g., demo@user.com).

Implementation Patterns

Core Workflow

  1. Define Developer Users: Configure users in config/filament-developer-logins.php:

    'users' => [
        'admin@example.com' => [
            'password' => 'password',
            'role' => 'admin',
        ],
        'editor@example.com' => [
            'password' => 'editor123',
            'role' => 'editor',
        ],
    ],
    
    • Supports email/password or username/password (configure via auth_identifier).
    • Optionally, use a database query to fetch users dynamically:
      'users' => [
          'query' => User::query()
              ->where('is_developer', true)
              ->select('email', 'password', 'role'),
      ],
      
  2. Customize the UI:

    • Grouping: Organize users by role or team:
      'groups' => [
          'Admins' => ['admin@example.com', 'superadmin@example.com'],
          'Editors' => ['editor@example.com'],
      ],
      
    • Icons/Colors: Use Filament’s built-in styling or override templates:
      'user_button' => FilamentDeveloperLoginsUserButton::make()
          ->icon('heroicon-o-user')
          ->color('success'),
      
  3. Integration with Filament Features:

    • Conditional Visibility: Show/hide the plugin based on environment:
      ->visible(app()->environment('local'))
      
    • Authentication Events: Listen for login events to trigger actions (e.g., log activity):
      FilamentDeveloperLogins::listen('logged-in', function (User $user) {
          event(new UserLoggedIn($user));
      });
      
  4. Multi-Panel Support: Register the plugin in each panel where needed:

    ->plugin(FilamentDeveloperLoginsPlugin::make()->forPanel('tenant'))
    

Advanced Patterns

  • Dynamic User Providers: Extend the UserProvider interface to fetch users from external APIs or caches:

    FilamentDeveloperLogins::extend('custom_provider', function () {
        return new CustomUserProvider();
    });
    
  • Rate Limiting: Protect against brute-force attempts by adding middleware:

    ->middleware([
        \Filament\Panel\Middleware\Authenticate::class,
        \Illuminate\Cache\Middleware\LimitRequests::class,
    ])
    
  • Localization: Translate button labels and messages:

    'labels' => [
        'login_as' => 'Login as User',
        'back_to_login' => 'Back to Login',
    ],
    

Gotchas and Tips

Common Pitfalls

  1. Password Hashing:

    • Issue: Hardcoded plain-text passwords in config are insecure.
    • Fix: Use php artisan filament:login to generate hashed passwords, then store them in the config:
      'users' => [
          'admin@example.com' => [
              'password' => '$2y...', // Hashed password
          ],
      ],
      
    • Alternative: Use Laravel’s Hash::make() in a migration or seeder.
  2. User Not Found:

    • Issue: The plugin fails silently if a user doesn’t exist.
    • Debug: Enable logging in the config:
      'debug' => true,
      
    • Fix: Ensure the auth_identifier (e.g., email) matches your User model’s fillable fields.
  3. CSRF Token Mismatch:

    • Issue: Clicking "Login as User" may redirect to a CSRF error.
    • Fix: Ensure the plugin is registered after Filament’s auth middleware in your panel’s routes:
      ->middleware([
          EnsureFrontendAssetsArePublished::class,
          VerifyCsrfToken::class, // Must come before FilamentDeveloperLogins
      ])
      
  4. Caching Headaches:

    • Issue: Changes to the users config aren’t reflected immediately.
    • Fix: Clear the config cache:
      php artisan config:clear
      
    • Tip: Use config_cache only in production.

Debugging Tips

  • Log User Logins: Add a listener to track activity:

    FilamentDeveloperLogins::listen('logged-in', function (User $user) {
        \Log::info("Developer login as {$user->email}", ['ip' => request()->ip()]);
    });
    
  • Inspect Requests: Dump the request payload before login:

    FilamentDeveloperLogins::listen('logging-in', function (array $data) {
        \Log::debug('Login attempt', $data);
    });
    
  • Test Locally: Use php artisan filament:login to verify users work before exposing them via the plugin.


Extension Points

  1. Custom User Buttons: Override the default button template:

    FilamentDeveloperLogins::macro('userButton', function () {
        return FilamentDeveloperLoginsUserButton::make()
            ->icon('heroicon-o-shield-check')
            ->extraAttributes(['class' => 'bg-blue-500']);
    });
    
  2. Pre-Login Actions: Run logic before a user logs in (e.g., set a session variable):

    FilamentDeveloperLogins::listen('before-login', function (User $user) {
        session()->put('developer_login', true);
    });
    
  3. Post-Login Redirects: Override the default redirect behavior:

    FilamentDeveloperLogins::macro('redirect', function (User $user) {
        return redirect()->route('filament.admin.pages.dashboard');
    });
    
  4. Environment-Specific Users: Load different users per environment:

    'users' => app()->environment('local')
        ? require __DIR__ . '/developer-users-local.php'
        : require __DIR__ . '/developer-users-staging.php',
    

Pro Tips

  • Combine with Filament Actions: Use the plugin to trigger actions like "Impersonate User" in a resource table:

    UseFilamentDeveloperLogins::make()
        ->label('Impersonate')
        ->action(function (User $record) {
            FilamentDeveloperLogins::loginAs($record);
        }),
    
  • Git Ignore: Exclude the config file if it contains sensitive data:

    config/filament-developer-logins.php
    
  • CI/CD Safety: Never commit plain-text passwords. Use environment variables or Laravel’s .env:

    FILAMENT_DEVELOPER_LOGINS_PASSWORD_ADMIN=hashed_password_here
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge