Fix login
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
|
||||
namespace Hutopy.Application.Users.Commands;
|
||||
public record LoginCommand : IRequest<string>
|
||||
{
|
||||
public required string EmailAddress { get; init; }
|
||||
public required string Password { get; init; }
|
||||
}
|
||||
|
||||
public class LoginCommandHandler : IRequestHandler<LoginCommand, string>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
private readonly IIdentityService _identityService;
|
||||
public record LoginCommand(
|
||||
string Email,
|
||||
string Password)
|
||||
: IRequest<LoginResponse>;
|
||||
|
||||
public LoginCommandHandler(IApplicationDbContext context, IIdentityService identityService)
|
||||
{
|
||||
_context = context;
|
||||
_identityService = identityService;
|
||||
}
|
||||
public record LoginResponse(
|
||||
string AccessToken,
|
||||
string RefreshToken);
|
||||
|
||||
public async Task<string> Handle(LoginCommand request, CancellationToken cancellationToken)
|
||||
public class LoginCommandHandler(
|
||||
IApplicationDbContext Context,
|
||||
IIdentityService identityService)
|
||||
: IRequestHandler<LoginCommand, LoginResponse>
|
||||
{
|
||||
var jwt = await _identityService.LoginAsync(request.EmailAddress, request.Password);
|
||||
public async Task<LoginResponse> Handle(LoginCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var accessToken = await identityService.LoginAsync(request.Email, request.Password);
|
||||
|
||||
return jwt ?? "Invalid login credentials";
|
||||
if (string.IsNullOrWhiteSpace(accessToken)) throw new InvalidOperationException("Invalid login credentials");
|
||||
|
||||
return new LoginResponse(accessToken, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Users : EndpointGroupBase
|
||||
return await sender.Send(query);
|
||||
}
|
||||
|
||||
private static async Task<string> Login(ISender sender, LoginCommand command)
|
||||
private static async Task<LoginResponse> Login(ISender sender, LoginCommand command)
|
||||
{
|
||||
return await sender.Send(command);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user