form->getState(); // Check credentials without logging in $user = User::where('email', $data['email'])->first(); if ($user && \Hash::check($data['password'], $user->password)) { // Check if 2FA is enabled if ($user->two_factor_secret && $user->two_factor_confirmed_at) { // Store user ID in session for 2FA challenge session(['login.id' => $user->id]); session(['login.remember' => $data['remember'] ?? false]); // Redirect to 2FA challenge $this->redirect(route('filament.jabali.auth.two-factor-challenge')); return null; } } $response = parent::authenticate(); // If authentication successful, check if user is admin $user = Filament::auth()->user(); if ($user && $user->is_admin) { // Log out from user panel guard Filament::auth()->logout(); // Redirect admins to admin panel using Livewire's redirect $this->redirect(route('filament.admin.pages.dashboard')); return null; } return $response; } }