Error handling on signup, login and home view

This commit is contained in:
2026-03-10 20:35:52 +01:00
parent f4b986c79e
commit 6a3fd249a4
6 changed files with 54 additions and 18 deletions

View File

@@ -7,7 +7,7 @@ public class MaxLengthRule : AbstractRule
{
private readonly string _stringValue;
private readonly int _maximumLentgh;
protected override string ErrorCode => "minimum_length";
protected override string ErrorCode => "maximum_length";
protected override string ErrorMessage
=> $"Length of '{ValueObjectName}' must be at most {_maximumLentgh} characters";

View File

@@ -10,12 +10,10 @@ namespace AipsCore.Infrastructure.Authentication.AuthService;
public class EfAuthService : IAuthService
{
private readonly AipsDbContext _dbContext;
private readonly UserManager<Persistence.User.User> _userManager;
public EfAuthService(AipsDbContext dbContext, UserManager<Persistence.User.User> userManager)
public EfAuthService(UserManager<Persistence.User.User> userManager)
{
_dbContext = dbContext;
_userManager = userManager;
}
@@ -27,8 +25,8 @@ public class EfAuthService : IAuthService
if (!result.Succeeded)
{
var errors = string.Join(", ", result.Errors.Select(e => e.Description));
throw new Exception($"User registration failed: {errors}");
var validationErrors = result.Errors.Select(e => new ValidationError(e.Code, e.Description)).ToList();
throw new ValidationException(validationErrors);
}
await _userManager.AddToRoleAsync(entity, UserRole.User.Name);