Skip to content

Commit

Permalink
add validation before the page is rendered (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarJose123 committed Jan 22, 2024
2 parents d9646ed + 8da448e commit 1faca7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/Http/Livewire/LockerScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Filament\Facades\Filament;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Pages\Actions\ActionGroup;
use Filament\Pages\BasePage;
use Filament\Pages\Concerns\InteractsWithFormActions;
use Filament\Forms\Contracts\HasForms;
Expand Down Expand Up @@ -35,6 +36,14 @@ class LockerScreen extends BasePage

public function mount()
{
// Check if the request is still authenticated or not before rendering the page,
// if not authenticated then redirect to the default filament login page

if(!Filament::auth()->check())
{
return redirect(Filament::getDefaultPanel()->getLoginUrl());
}

session(['lockscreen' => true]);
if (! config('filament-lockscreen.enable_redirect_to')) {
if (! session()->has('next') || session()->get('next') === null) {
Expand All @@ -43,7 +52,7 @@ public function mount()
}
}

protected function forceLogout()
protected function forceLogout(): void
{
Filament::auth()->logout();
session()->invalidate();
Expand All @@ -56,7 +65,7 @@ protected function forceLogout()
->send();
}

public function authenticate()
public function authenticate(): \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse|\Illuminate\Contracts\Foundation\Application|null
{
$data = $this->form->getState();
$this->account_password_field = config('filament-lockscreen.table_columns.account_password_field');
Expand Down
5 changes: 2 additions & 3 deletions src/Http/Middleware/Locker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class Locker
*/
public function handle($request, Closure $next)
{

if ($request->session()->get('lockscreen') && $request->method() === 'GET') {
$panelId = filament()->getCurrentPanel()->getId();
if ($request->method() === 'GET' && $request->session()->get('lockscreen') ) {
$panelId = filament()->getCurrentPanel()?->getId();
return redirect()->route("lockscreen.{$panelId}.page");
}
return $next($request);
Expand Down

0 comments on commit 1faca7e

Please sign in to comment.