Fixes redirection after authentication

This commit is contained in:
BinaryAlley committed 2024-11-16 18:14:57 +02:00
1 parent 5751d3a2f0
commit 805b5deb40
3 files changed
+9 -6

No files matched your search

@@ -129,11 +129,10 @@ public class AuthController : Controller
/// Logs in an account.
/// </summary>
/// <param name="data">User credentials used for login.</param>
/// <param name="returnUrl">The url to return to, after login (if any).</param>
[AllowAnonymous]
[ValidateAntiForgeryToken]
[HttpPost("login")]
public async Task<IActionResult> Login([FromBody] LoginRequestModel data, string? returnUrl = null)
public async Task<IActionResult> Login([FromBody] LoginRequestModel data)
{
try
{
@@ -158,7 +157,7 @@ public class AuthController : Controller
ClaimsIdentity claimsIdentity = new(claims, CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
// return success status and redirect URL
return Json(new { success = true, data = string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl) ? Url.Content("~/") : Url.Content(returnUrl) });
return Json(new { success = true, data = string.IsNullOrEmpty(data.ReturnUrl) || !Url.IsLocalUrl(data.ReturnUrl) ? Url.Content("~/") : Url.Content(data.ReturnUrl) });
}
catch (ApiException ex)
{