F
Filament16mo ago
πTeR

Multiple login models

Hello, how can I use multiple models to diferent logins? Like user model and consumermodel? I tried to build diferent panels and set a Login class in a customer panel, like that:
return $panel
->id('app')
->path('app')
->login(**AppLogin::class**)
return $panel
->id('app')
->path('app')
->login(**AppLogin::class**)
So, in AppLogin class, I have duplicated all default Login class ( Filament\Pages\Auth\Login.php) Well.. I think in the method I need to pass something to indicate I´d like to get Consumer models instead User model right?
public function authenticate(): ?LoginResponse
{
try {
$this->rateLimit(5);
} catch (TooManyRequestsException $exception) {
// Catch implementation
}
$data = $this->form->getState();

if (! Filament::auth()->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false)) {
throw ValidationException::withMessages([
'data.email' => __('filament-panels::pages/auth/login.messages.failed'),
]);
}

session()->regenerate();

return app(LoginResponse::class);
}
public function authenticate(): ?LoginResponse
{
try {
$this->rateLimit(5);
} catch (TooManyRequestsException $exception) {
// Catch implementation
}
$data = $this->form->getState();

if (! Filament::auth()->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false)) {
throw ValidationException::withMessages([
'data.email' => __('filament-panels::pages/auth/login.messages.failed'),
]);
}

session()->regenerate();

return app(LoginResponse::class);
}
But I really don´t know what I need to do here.. Someone can help me? Thanks
4 Replies
Dennis Koch
Dennis Koch16mo ago
Auth guards are the way to go.
Emmanuel
Emmanuel16mo ago
You will need to define a new AuthGuard guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'token', 'provider' => 'users', 'hash' => false, ],
'consumer' => [ 'driver' => 'session', 'provider' => 'consumers', ], ], And then associate the provider with your model 'providers' => [ 'consumers' => [ 'driver' => 'eloquent', 'model' => App\Consumers::class, ], Then use the new AuthGuard in the filament panel
πTeR
πTeROP16mo ago
Thank you guys, awesome help 💪 Appreciate it 🚀
Want results from more Discord servers?
Add your server