From 0237efa8ac688988d35a407ca1d4d0fbb0293736 Mon Sep 17 00:00:00 2001 From: Artem Dudarev Date: Mon, 26 Aug 2024 17:58:54 +0200 Subject: [PATCH] fix: Fix 401 error on sign in page (#2829) --- .../Controllers/Api/SecurityController.cs | 6 ++++++ .../wwwroot/js/app/security/security.js | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/VirtoCommerce.Platform.Web/Controllers/Api/SecurityController.cs b/src/VirtoCommerce.Platform.Web/Controllers/Api/SecurityController.cs index 2d3275320e0..13c9976ab81 100644 --- a/src/VirtoCommerce.Platform.Web/Controllers/Api/SecurityController.cs +++ b/src/VirtoCommerce.Platform.Web/Controllers/Api/SecurityController.cs @@ -159,9 +159,15 @@ public async Task Logout() /// [HttpGet] [Authorize] + [AllowAnonymous] [Route("currentuser")] public async Task> GetCurrentUser() { + if (User.Identity?.IsAuthenticated != true) + { + return Ok(new { }); + } + var user = await UserManager.FindByNameAsync(CurrentUserName); if (user == null) { diff --git a/src/VirtoCommerce.Platform.Web/wwwroot/js/app/security/security.js b/src/VirtoCommerce.Platform.Web/wwwroot/js/app/security/security.js index 80b3e74919e..30f8c6dd216 100644 --- a/src/VirtoCommerce.Platform.Web/wwwroot/js/app/security/security.js +++ b/src/VirtoCommerce.Platform.Web/wwwroot/js/app/security/security.js @@ -52,10 +52,10 @@ angular.module('platformWebApp') $scope.loginProgress = true; // Try to login authService.login($scope.user.email, $scope.user.password, $scope.user.remember).then( - function (loggedIn) { - if (!loggedIn) { - $scope.loginProgress = false; - $scope.authError = 'invalidCredentials'; + function (result) { + $scope.loginProgress = false; + if (!result || !result.succeeded) { + $scope.authError = 'The login or password is incorrect.'; } }, function (x) { @@ -72,7 +72,7 @@ angular.module('platformWebApp') }); }; - $scope.togglePassword = function() { + $scope.togglePassword = function () { $scope.showPassword = !$scope.showPassword; } });