@@ -16,8 +16,11 @@ class Login extends BaseLogin
16
16
{
17
17
public function authenticate (): null |TwoFactorAuthResponse |LoginResponse
18
18
{
19
- if ($ response = $ this ->handleRateLimiting ()) {
20
- return $ response ;
19
+ $ this ->handleRateLimiting ();
20
+
21
+ // Stop execution if there are validation errors
22
+ if ($ this ->getErrorBag ()->isNotEmpty ()) {
23
+ return null ;
21
24
}
22
25
23
26
$ data = $ this ->form ->getState ();
@@ -30,8 +33,11 @@ public function authenticate(): null|TwoFactorAuthResponse|LoginResponse
30
33
31
34
$ user = Filament::auth ()->user ();
32
35
33
- if ($ response = $ this ->handleTwoFactorAuthentication ($ user , $ credentials , $ remember )) {
34
- return $ response ;
36
+ if ($ this ->needsTwoFactorAuthentication ($ user )) {
37
+ $ this ->storeCredentials ($ credentials , $ remember );
38
+ Filament::auth ()->logout ();
39
+
40
+ return app (TwoFactorAuthResponse::class);
35
41
}
36
42
37
43
if (! $ this ->userCanAccessPanel ($ user )) {
@@ -47,16 +53,20 @@ public function authenticate(): null|TwoFactorAuthResponse|LoginResponse
47
53
/**
48
54
* Handle rate limiting for login attempts.
49
55
*/
50
- protected function handleRateLimiting (): ? LoginResponse
56
+ protected function handleRateLimiting (): void
51
57
{
52
58
try {
53
59
$ this ->rateLimit (5 );
54
60
} catch (TooManyRequestsException $ exception ) {
61
+ // Optionally send a notification (can be omitted if not needed)
55
62
$ this ->getRateLimitedNotification ($ exception )?->send();
56
- return null ;
57
- }
58
63
59
- return null ;
64
+ // Use the available property to get the number of seconds
65
+ $ this ->addError ('email ' , __ ('auth.throttle ' , ['seconds ' => $ exception ->secondsUntilAvailable ]));
66
+
67
+ // Stop further execution by returning early
68
+ return ;
69
+ }
60
70
}
61
71
62
72
/**
@@ -73,7 +83,7 @@ protected function attemptLogin(array $credentials, bool $remember): bool
73
83
protected function handleTwoFactorAuthentication (Authenticatable $ user , array $ credentials , bool $ remember ): ?TwoFactorAuthResponse
74
84
{
75
85
if ($ this ->needsTwoFactorAuthentication ($ user )) {
76
- $ this ->flashCredentials ($ credentials , $ remember );
86
+ $ this ->storeCredentials ($ credentials , $ remember );
77
87
Filament::auth ()->logout ();
78
88
79
89
return app (TwoFactorAuthResponse::class);
@@ -101,9 +111,10 @@ protected function userCanAccessPanel(Authenticatable $user): bool
101
111
}
102
112
103
113
/**
104
- * Flash the credentials into the session, encrypted.
114
+ * Save credentials to session encrypted.
115
+ * Flash not possible with Filament as Livewire call would clear them before they can be used
105
116
*/
106
- protected function flashCredentials (array $ credentials , bool $ remember ): void
117
+ protected function storeCredentials (array $ credentials , bool $ remember ): void
107
118
{
108
119
$ encryptedCredentials = array_map (
109
120
fn ($ value ) => Crypt::encryptString ($ value ),
@@ -117,10 +128,6 @@ protected function flashCredentials(array $credentials, bool $remember): void
117
128
118
129
$ credentialKey = config ('filament-2fa.login.credential_key ' );
119
130
120
- if (config ('filament-2fa.login.flashLoginCredentials ' )) {
121
- request ()->session ()->flash ($ credentialKey , $ sessionData );
122
- } else {
123
- session ([$ credentialKey => $ sessionData ]);
124
- }
131
+ session ([$ credentialKey => $ sessionData ]);
125
132
}
126
133
}
0 commit comments