Skip to content

Commit 935e594

Browse files
author
CIS Guru
committed
fix: Prevent login form double submission causing blank page redirect
Added submission guard to prevent multiple rapid clicks on login button: - Added isSubmitting flag to track login operation state - Early return if already submitting (prevents concurrent logins) - Disabled submit button during login process - Visual feedback: spinner and 'Logging in...' text while submitting - Error message cleared on new submission attempt - finally block ensures flag reset even on exceptions Fixes issue where clicking login button multiple times redirected user to blank page due to concurrent authentication attempts.
1 parent 4039221 commit 935e594

1 file changed

Lines changed: 45 additions & 20 deletions

File tree

  • 4-Aquiis.SimpleStart/Shared/Components/Account/Pages

4-Aquiis.SimpleStart/Shared/Components/Account/Pages/Login.razor

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@
3939
</label>
4040
</div>
4141
<div>
42-
<button type="submit" class="w-100 btn btn-lg btn-primary">Log in</button>
42+
<button type="submit" class="w-100 btn btn-lg btn-primary" disabled="@isSubmitting">
43+
@if (isSubmitting)
44+
{
45+
<span class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"></span>
46+
<span>Logging in...</span>
47+
}
48+
else
49+
{
50+
<span>Log in</span>
51+
}
52+
</button>
4353
</div>
4454
<div>
4555
<p>
@@ -66,6 +76,7 @@
6676

6777
@code {
6878
private string? errorMessage;
79+
private bool isSubmitting = false;
6980

7081
[CascadingParameter]
7182
private HttpContext HttpContext { get; set; } = default!;
@@ -103,28 +114,42 @@
103114

104115
public async Task LoginUser()
105116
{
106-
// This doesn't count login failures towards account lockout
107-
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
108-
var result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
109-
if (result.Succeeded)
110-
{
111-
Logger.LogInformation("User logged in.");
112-
RedirectManager.RedirectTo(ReturnUrl);
113-
}
114-
else if (result.RequiresTwoFactor)
115-
{
116-
RedirectManager.RedirectTo(
117-
"Account/LoginWith2fa",
118-
new() { ["returnUrl"] = ReturnUrl, ["rememberMe"] = Input.RememberMe });
119-
}
120-
else if (result.IsLockedOut)
117+
// Prevent double submission
118+
if (isSubmitting)
119+
return;
120+
121+
try
121122
{
122-
Logger.LogWarning("User account locked out.");
123-
RedirectManager.RedirectTo("Account/Lockout");
123+
isSubmitting = true;
124+
errorMessage = null;
125+
126+
// This doesn't count login failures towards account lockout
127+
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
128+
var result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
129+
if (result.Succeeded)
130+
{
131+
Logger.LogInformation("User logged in.");
132+
RedirectManager.RedirectTo(ReturnUrl);
133+
}
134+
else if (result.RequiresTwoFactor)
135+
{
136+
RedirectManager.RedirectTo(
137+
"Account/LoginWith2fa",
138+
new() { ["returnUrl"] = ReturnUrl, ["rememberMe"] = Input.RememberMe });
139+
}
140+
else if (result.IsLockedOut)
141+
{
142+
Logger.LogWarning("User account locked out.");
143+
RedirectManager.RedirectTo("Account/Lockout");
144+
}
145+
else
146+
{
147+
errorMessage = "Error: Invalid login attempt.";
148+
}
124149
}
125-
else
150+
finally
126151
{
127-
errorMessage = "Error: Invalid login attempt.";
152+
isSubmitting = false;
128153
}
129154
}
130155

0 commit comments

Comments
 (0)