Customize Login process for multiple panels and "user" models.

Hello all, my apologies for noob question, as I'm not experienced developer and I'm still learning. Documentation is not understandable for me in this case, trying Googling, but no luck. (probably my bad english as I'm probably asking wrong) Today, it's my first time with V3. In V2, i've tried to do a custom login behaviour with custom page (by some tutorial) and it's working great. Now, I'm trying to do the same thing in V3. What I'm trying to do: In basic, I will have different panels (admin, app, wms, ...). and each panel will use different model for login (users, employees, etc.) with custom login behaviour (employee will login with personal no., check user is_active, etc.). Kindly asking, can somebody just point me right direction how to do this in V3 explained step by step what to do "for noobs" ? Many thanks for your help 😉
3 Replies
Michal Čabala
Michal Čabala9mo ago
Code example what I have in V2 in App/Filament/Pages/Login.php ... class Login extends FilamentLogin { public function mount(): void { parent::mount(); if (Filament::auth()->check()) { redirect()->intended(Filament::getUrl()); } if (app()->environment('local')) { $this->form->fill([ 'username' => '', 'password' => '', ]); } } protected function getFormSchema(): array { return [ TextInput::make('username') ->label('Uživatelské jméno') ->required() ->autocomplete(), TextInput::make('password') ->label(('filament::login.fields.password.label')) ->password() ->required(), Checkbox::make('remember') ->label(('filament::login.fields.remember.label')), ]; } public function authenticate(): ?LoginResponse { try { $this->rateLimit(5); } catch (TooManyRequestsException $exception) { throw ValidationException::withMessages([ 'username' => ('filament::login.messages.throttled', [ 'seconds' => $exception->secondsUntilAvailable, 'minutes' => ceil($exception->secondsUntilAvailable / 60), ]), ]); } $data = $this->form->getState(); if (!Filament::auth()->attempt([ 'username' => $data['username'], 'password' => $data['password'], 'is_active' => 1, ], $data['remember'])) { throw ValidationException::withMessages([ 'username' => ('filament::login.messages.failed'), ]); } session()->regenerate(); return app(LoginResponse::class); } } ...
awsqed
awsqed9mo ago
you can specify the class to handle login and change the auth guard using for panel https://filamentphp.com/docs/3.x/panels/users#customizing-the-authentication-features i assume you already have different auth guards and providers in config/auth.php you just need to create different login class with different logic, then use it with ->login(AdminLogin::class) in the panel provider
Arko
Arko9mo ago
^ as they show how to override the profile(), you can also override the Login class using ->login(YourLoginClass::class) in which you can customize the login.