Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Allow register page customisation and fix tenancy issue #22

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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