Skip to content

Commit

Permalink
login successful page enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
lstlamc committed Jan 8, 2025
1 parent 60d2b96 commit 9b790b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/FilamentEmail2faPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace Solutionforest\FilamentEmail2fa;

use Filament\Contracts\Plugin;
use Filament\Pages\Page;
use Filament\Panel;
use Solutionforest\FilamentEmail2fa\Middlewares\IsTwoFAVerified;
use Solutionforest\FilamentEmail2fa\Pages\LoginSuccessPage;
use Solutionforest\FilamentEmail2fa\Pages\TwoFactorAuth;

class FilamentEmail2faPlugin implements Plugin
{
protected ?string $loginSuccessPage = null;

public function getId(): string
{
return 'filament-email-2fa';
Expand All @@ -18,11 +21,14 @@ public function getId(): string
public function register(Panel $panel): void
{
$fapage = config('filament-email-2fa.2fa_page', TwoFactorAuth::class);
$login_success_page = config('filament-email-2fa.login_success_page', LoginSuccessPage::class);
$pages = [];
if($this->loginSuccessPage == null){
$pages[] = config('filament-email-2fa.login_success_page', LoginSuccessPage::class);
}

$panel->pages([
$fapage,
$login_success_page,
...$pages,
])
->authMiddleware([
IsTwoFAVerified::class,
Expand All @@ -44,4 +50,16 @@ public static function get(): static

return $plugin;
}

public function loginSuccessPage(string $component): static
{
$this->loginSuccessPage = $component;

return $this;
}

public function getLoginSuccessPage(): string
{
return $this->loginSuccessPage ?? config('filament-email-2fa.login_success_page', LoginSuccessPage::class);
}
}
5 changes: 3 additions & 2 deletions src/Responses/LoginSuccessResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Solutionforest\FilamentEmail2fa\Responses;

use Filament\Facades\Filament;
use Filament\Http\Responses\Auth\Contracts\LoginResponse as LoginResponseContract;
use Solutionforest\FilamentEmail2fa\Pages\LoginSuccessPage;

Expand All @@ -15,8 +16,8 @@ class LoginSuccessResponse implements LoginResponseContract
*/
public function toResponse($request)
{
// return whatever you want as url
$page = Filament::getCurrentPanel()->getPlugin('filament-email-2fa')->getLoginSuccessPage();

Check failure on line 19 in src/Responses/LoginSuccessResponse.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Filament\Contracts\Plugin::getLoginSuccessPage().

return redirect()->intended(route(LoginSuccessPage::getRouteName()));
return redirect()->intended(route($page::getRouteName()));
}
}

0 comments on commit 9b790b5

Please sign in to comment.