Filament Breezy Documentation

repository·3.x·Indexed 22 days ago

https://github.com/jacobtims/filament-breezy

Enhanced security features for Filament v4+ Panels, providing profile management, two-factor authentication (2FA), passkeys, and session management. Includes tools for user avatars, Sanctum personal access tokens, and specialized actions like PasswordButtonAction and AuthenticatePasskeyAction to secure sensitive operations.

Tokens
5.2K
Snippets
25
Records
28
Agent score
77%

What's inside Filament Breezy

  1. How 2FA sessions work in Filament Breezy

    3.x

    Two-Factor Authentication (2FA) sessions in Breezy are governed by the following rules:

    • Guard Scope: By default, Breezy uses the same guard defined on your Filament Panel (defaulting to 'web'). Only panels that have registered the BreezyCore plugin have access to 2FA.
    • Multi-Panel Behavior: If multiple panels use 2FA and share the same guard, a user only needs to enter their OTP once for the duration of the session.
    • Session Lifetime: The 2FA session lasts for the duration of the Laravel session lifetime. Users must re-enter the OTP if they log out or if the session expires.
    • Interaction with Email Verification: When 2FA is configured, the user is prompted for the OTP code before being prompted for email verification (MustVerifyEmail).
  2. Register Filament Breezy in a Panel

    3.x

    To enable Breezy features, add the BreezyCore plugin to your Filament Panel configuration using the plugin() or plugins([]) method.

    use Jeffgreco13ilament-breezy\
    BreezyCore;
    
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                BreezyCore::make()
            ]);
    }
  3. Create and register custom My Profile components

    3.x

    You can add new custom Livewire components to the My Profile page by extending Jeffgreco13\FilamentBreezy\Livewire\MyProfileComponent and registering them with myProfileComponents().

    // 1. Create component extending MyProfileComponent
    class MyCustomComponent extends MyProfileComponent
    {
        // ... implement form() and submit()
    }
    
    // 2. Register with Breezy
    BreezyCore::make()
        ->myProfileComponents([MyCustomComponent::class])
    
    // 3. Or override an existing component
    BreezyCore::make()
        ->myProfileComponents([
            'update_password' => MyCustomComponent::class,
        ])
  4. Install Filament Breezy

    3.x

    To install Filament Breezy, first require the package via Composer and then run the provided artisan installation command to set up the necessary components.

    composer require jeffgreco13/filament-breezy
    php artisan breezy:install
  5. Enable Two Factor Authentication (2FA)

    3.x
    1. Add the Jeffgreco13\FilamentBreezy\Traits\TwoFactorAuthenticatable trait to your User model.
    2. Enable it in the Breezy configuration using enableTwoFactorAuthentication().
    // In User model
    class User extends Authenticatable
    {
        use TwoFactorAuthenticatable;
    }
    
    // In Breezy configuration
    BreezyCore::make()
        ->enableTwoFactorAuthentication(
            force: false, // force user to enable 2FA
            action: CustomTwoFactorPage::class, // optional custom page
            authMiddleware: MustTwoFactor::class, // optional custom middleware
            scopeToPanel: true, // scope 2FA to current panel
        )
  6. Integrate Tailwind classes for Filament Breezy

    3.x

    Because Filament Breezy uses additional Tailwind classes, you should add its view paths to your custom Filament theme's CSS file (typically located at resources/css/filament/admin/theme.css) to ensure styles are compiled correctly.

    Add the following @source directive to your CSS file:

    @source '../../../../vendor/jeffgreco13/filament-breezy/resources/**/*';
  7. Update the Filament auth guard

    3.x

    Breezy uses the authGuard defined on your Filament Panel. You can customize this in your PanelProvider. Ensure that the model used by your chosen guard extends Laravel's Authenticatable class.

    use Jeffgreco13ilament-breezy\BreezyCore;
    
    class CustomersPanelProvider extends PanelProvider
    {
        public function panel(Panel $panel): Panel
        {
            return $panel
                ...
                ->authGuard('customers')
                ->plugin(
                    BreezyCore::make()
                );
        }
    }
  8. Upgrade from Filament Breezy v2.x to v3.0

    3.x

    Upgrading to version 3.0 introduces breaking changes regarding environment requirements and syntax.

    Requirements

    • PHP: Version 8.2 or higher is required.
    • Filament: Filament V4 is required.

    Upgrade Steps

    1. Update Composer dependency Update your composer.json to require version ^3.0:
    "jeffgreco13/filament-breezy": "^3.0",
    1. Integrate Tailwind classes Filament V4 requires a custom theme to support plugin Tailwind classes. After creating your custom theme, you must add Breezy's view paths to your theme's CSS file (typically located at resources/css/filament/admin/theme.css) using the @source directive:
    @source '../../../../vendor/jeffgreco13/filament-breezy/resources/**/*';
    1. Update Published Views or Custom Components If you have previously published Breezy views or implemented custom profile components, you must update them to use the new Filament component syntax. Ensure you are using <x-filament::section> and <x-filament::button> as appropriate.
  9. Setup and customize user avatars

    3.x

    To use avatars, your User model must implement Filament\Models\Contracts\HasAvatar and provide a getFilamentAvatarUrl() method. You must also add an avatar_url column to your users table.

    To customize the upload component, use avatarUploadComponent().

    // In your User model
    class User extends Authenticatable implements FilamentUser, HasAvatar
    {
        public function getFilamentAvatarUrl(): ?string
        {
            return $this->avatar_url ? Storage::url($this->avatar_url) : null;
        }
    }
    
    // In your Breezy configuration
    BreezyCore::make()
        ->avatarUploadComponent(fn() => FileUpload::make('avatar_url')->disk('profile-photos'))
  10. Use the TwoFactorAuthenticatable trait on your User model

    3.x

    For the TwoFactorAuthentication Livewire component and other Breezy 2FA features to work, your User model must implement the Jeffgreco13\FilamentBreezy\Traits\TwoFactorAuthenticatable trait. This trait provides the necessary methods used by the component, such as:

    • enableTwoFactorAuthentication()
    • disableTwoFactorAuthentication()
    • confirmTwoFactorAuthentication()
    • setTwoFactorSession()
    • reGenerateRecoveryCodes()
    • getTwoFactorQrCodeUrl()