Skip to content

Commit

Permalink
[Feature] Allow register page customisation and fix tenancy issue (#22)
Browse files Browse the repository at this point in the history
* Add more config values to customize register and menu items

* Fix styling

* Prevent duplicate array key

* wip

---------

Co-authored-by: Baspa <[email protected]>
  • Loading branch information
Baspa and Baspa authored Aug 28, 2024
1 parent c29b567 commit c2bb853
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ return [
// ...

'login' => Login::class,
'register' => Register::class,
'challenge' => LoginTwoFactor::class,
'two_factor_settings' => TwoFactor::class,
'password_reset' => PasswordReset::class,
Expand All @@ -190,6 +191,24 @@ return [

Make sure you extend the original classes from the package.

### Multi-tenant setup

If you're using Filament in a multi-tenant setup, you need to set the `tenant` option to `true` in the `config/filament-two-factor-auth.php` file. You also need to set the `userMenuItems` in your panel config. Take a look at the example below:

```php
use Vormkracht10\TwoFactorAuth\Pages\TwoFactor;

// ...

->userMenuItems([
// ...
'two-factor-authentication' => MenuItem::make()
->icon('heroicon-o-lock-closed')
->label(__('Two-Factor Authentication'))
->url(fn(): string => TwoFactor::getUrl(['tenant' => auth()->user()->organization->getRouteKey()])),
])
```

## Testing

```bash
Expand Down
26 changes: 26 additions & 0 deletions config/filament-two-factor-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\LoginTwoFactor;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\PasswordConfirmation;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\PasswordReset;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\Register;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\RequestPasswordReset;
use Vormkracht10\TwoFactorAuth\Pages\TwoFactor;

Expand All @@ -27,6 +28,30 @@
TwoFactorType::authenticator,
],

'enabled_features' => [
/*
|--------------------------------------------------------------------------
| Register
|--------------------------------------------------------------------------
|
| This value determines whether users may register in the application.
|
*/
'register' => true,

/*
|--------------------------------------------------------------------------
| Tenant
|--------------------------------------------------------------------------
|
| Set to true if you're using Filament in a multi-tenant setup. If true, you
| need to manually set the user menu item for the two factor authentication
| page panel class. Take a look at the documentation for more information.
|
*/
'multi_tenancy' => false,
],

/*
|--------------------------------------------------------------------------
| SMS Service
Expand All @@ -49,6 +74,7 @@
|
*/
'login' => Login::class,
'register' => Register::class,
'challenge' => LoginTwoFactor::class,
'two_factor_settings' => TwoFactor::class,
'password_reset' => PasswordReset::class,
Expand Down
19 changes: 13 additions & 6 deletions src/TwoFactorAuthPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@ public function register(Panel $panel): void
{
$panel
->login(config('filament-two-factor-auth.login'))
->userMenuItems([
'two-factor-authentication' => MenuItem::make()
->icon('heroicon-o-lock-closed')
->label(__('Two-Factor Authentication'))
->url(fn (): string => TwoFactor::getUrl()),
])
->pages([
config('filament-two-factor-auth.two_factor_settings'),
config('filament-two-factor-auth.challenge'),
])
->viteTheme('vendor/vormkracht10/filament-2fa/resources/dist/filament-two-factor-auth.css');

if (! config('filament-two-factor-auth.enabled_features.multi_tenancy')) {
$panel->userMenuItems([
'two-factor-authentication' => MenuItem::make()
->icon('heroicon-o-lock-closed')
->label(__('Two-Factor Authentication'))
->url(fn (): string => TwoFactor::getUrl()),
]);
}

if (config('filament-two-factor-auth.enabled_features.register')) {
$panel->registration(config('filament-two-factor-auth.register'));
}
}

public function boot(Panel $panel): void
Expand Down

0 comments on commit c2bb853

Please sign in to comment.