Skip to content

Commit 3bb7795

Browse files
authored
Fix places returning after navigation was expected. (#62105)
1 parent 7bedc4b commit 3bb7795

File tree

6 files changed

+32
-18
lines changed

6 files changed

+32
-18
lines changed

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Account/Pages/ExternalLogin.razor

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@
7272
if (RemoteError is not null)
7373
{
7474
RedirectManager.RedirectToWithStatus("Account/Login", $"Error from external provider: {RemoteError}", HttpContext);
75+
return;
7576
}
7677

7778
var info = await SignInManager.GetExternalLoginInfoAsync();
7879
if (info is null)
7980
{
8081
RedirectManager.RedirectToWithStatus("Account/Login", "Error loading external login information.", HttpContext);
82+
return;
8183
}
8284

8385
externalLoginInfo = info;
@@ -118,6 +120,7 @@
118120
externalLoginInfo.Principal.Identity?.Name,
119121
externalLoginInfo.LoginProvider);
120122
RedirectManager.RedirectTo(ReturnUrl);
123+
return;
121124
}
122125
else if (result.IsLockedOut)
123126
{
@@ -168,13 +171,17 @@
168171
{
169172
RedirectManager.RedirectTo("Account/RegisterConfirmation", new() { ["email"] = Input.Email });
170173
}
171-
172-
await SignInManager.SignInAsync(user, isPersistent: false, externalLoginInfo.LoginProvider);
173-
RedirectManager.RedirectTo(ReturnUrl);
174+
else
175+
{
176+
await SignInManager.SignInAsync(user, isPersistent: false, externalLoginInfo.LoginProvider);
177+
RedirectManager.RedirectTo(ReturnUrl);
178+
}
174179
}
175180
}
176-
177-
message = $"Error: {string.Join(",", result.Errors.Select(error => error.Description))}";
181+
else
182+
{
183+
message = $"Error: {string.Join(",", result.Errors.Select(error => error.Description))}";
184+
}
178185
}
179186

180187
private ApplicationUser CreateUser()

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Account/Pages/Manage/ExternalLogins.razor

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@
123123
{
124124
RedirectManager.RedirectToCurrentPageWithStatus("Error: The external login was not removed.", HttpContext);
125125
}
126-
127-
await SignInManager.RefreshSignInAsync(user);
128-
RedirectManager.RedirectToCurrentPageWithStatus("The external login was removed.", HttpContext);
126+
else
127+
{
128+
await SignInManager.RefreshSignInAsync(user);
129+
RedirectManager.RedirectToCurrentPageWithStatus("The external login was removed.", HttpContext);
130+
}
129131
}
130132

131133
private async Task OnGetLinkLoginCallbackAsync()
@@ -145,14 +147,16 @@
145147
}
146148

147149
var result = await UserManager.AddLoginAsync(user, info);
148-
if (!result.Succeeded)
150+
if (result.Succeeded)
151+
{
152+
// Clear the existing external cookie to ensure a clean login process
153+
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
154+
155+
RedirectManager.RedirectToCurrentPageWithStatus("The external login was added.", HttpContext);
156+
}
157+
else
149158
{
150159
RedirectManager.RedirectToCurrentPageWithStatus("Error: The external login was not added. External logins can only be associated with one account.", HttpContext);
151160
}
152-
153-
// Clear the existing external cookie to ensure a clean login process
154-
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
155-
156-
RedirectManager.RedirectToCurrentPageWithStatus("The external login was added.", HttpContext);
157161
}
158162
}

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Account/Pages/Manage/Index.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
if (!setPhoneResult.Succeeded)
7373
{
7474
RedirectManager.RedirectToCurrentPageWithStatus("Error: Failed to set phone number.", HttpContext);
75+
return;
7576
}
7677
}
7778

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Account/Pages/Manage/PersonalData.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
if (user is null)
3838
{
3939
RedirectManager.RedirectToInvalidUser(UserManager, HttpContext);
40-
return;
4140
}
4241
}
4342
}

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Account/Pages/Register.razor

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@
9797
"Account/RegisterConfirmation",
9898
new() { ["email"] = Input.Email, ["returnUrl"] = ReturnUrl });
9999
}
100-
101-
await SignInManager.SignInAsync(user, isPersistent: false);
102-
RedirectManager.RedirectTo(ReturnUrl);
100+
else
101+
{
102+
await SignInManager.SignInAsync(user, isPersistent: false);
103+
RedirectManager.RedirectTo(ReturnUrl);
104+
}
103105
}
104106

105107
private ApplicationUser CreateUser()

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Account/Pages/ResetPassword.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
if (result.Succeeded)
7979
{
8080
RedirectManager.RedirectTo("Account/ResetPasswordConfirmation");
81+
return;
8182
}
8283

8384
identityErrors = result.Errors;

0 commit comments

Comments
 (0)