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

Add forced() method and middleware #28

Merged
merged 15 commits into from
Sep 15, 2024
3 changes: 2 additions & 1 deletion resources/views/two-factor.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<x-filament-panels::page>

<div class="space-y-10 divide-y divide-gray-900/10 ">
<div class="grid grid-cols-1 gap-x-8 gap-y-8 pt-10 md:grid-cols-3">
<div class="pr-4 sm:px-0">
<h2 class="text-base font-semibold leading-7 dark:bg-white">
{{ __('Secure your account') }}
{{ __('Secure your account') }} sdfsadfsa
</h2>

@if (!$showingRecoveryCodes && $user->two_factor_confirmed_at)
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Middleware/ForceTwoFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public function handle(Request $request, Closure $next): mixed
if ($currentPanel) {
return redirect()->to(route('filament.' . $currentPanel->getId() . '.pages.two-factor', [
'tenant' => Filament::getTenant(),
]));
]))->with('two_factor_redirect_message', __('Your administrator requires you to enable two-factor authentication.'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this customizable?
Example:

->forced(message: __('Some message')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes maybe it's better to let the developer choose which message to show to the user. I'm also not really satisfied with showing the message yet. Weird enough I couldn't show the message in the blade view itself using the session helper..

}
}

return $next($request);
}
}
}
10 changes: 9 additions & 1 deletion src/Pages/TwoFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public function getTitle(): string | Htmlable

public function mount(): void
{
if (session('two_factor_redirect_message')) {
Notification::make()
->title(session('two_factor_redirect_message'))
->danger()
->persistent()
->send();
}

$this->twoFactorOptionsCount = config('filament-two-factor-auth.options') ? count(config('filament-two-factor-auth.options')) : 0;

$this->user = Auth::user();
Expand Down Expand Up @@ -272,4 +280,4 @@ public function regenerateRecoveryCodes(GenerateNewRecoveryCodes $generate): voi

$this->showingRecoveryCodes = true;
}
}
}