diff --git a/src/Application/Users/Commands/Login.cs b/src/Application/Users/Commands/Login.cs index f61f810..8f232b5 100644 --- a/src/Application/Users/Commands/Login.cs +++ b/src/Application/Users/Commands/Login.cs @@ -1,27 +1,27 @@ using Hutopy.Application.Common.Interfaces; namespace Hutopy.Application.Users.Commands; -public record LoginCommand : IRequest + +public record LoginCommand( + string Email, + string Password) + : IRequest; + +public record LoginResponse( + string AccessToken, + string RefreshToken); + +public class LoginCommandHandler( + IApplicationDbContext Context, + IIdentityService identityService) + : IRequestHandler { - public required string EmailAddress { get; init; } - public required string Password { get; init; } -} - -public class LoginCommandHandler : IRequestHandler -{ - private readonly IApplicationDbContext _context; - private readonly IIdentityService _identityService; - - public LoginCommandHandler(IApplicationDbContext context, IIdentityService identityService) + public async Task Handle(LoginCommand request, CancellationToken cancellationToken) { - _context = context; - _identityService = identityService; - } + var accessToken = await identityService.LoginAsync(request.Email, request.Password); - public async Task Handle(LoginCommand request, CancellationToken cancellationToken) - { - var jwt = await _identityService.LoginAsync(request.EmailAddress, request.Password); + if (string.IsNullOrWhiteSpace(accessToken)) throw new InvalidOperationException("Invalid login credentials"); - return jwt ?? "Invalid login credentials"; + return new LoginResponse(accessToken, string.Empty); } } diff --git a/src/Web/Endpoints/Users.cs b/src/Web/Endpoints/Users.cs index b2a15c5..c344509 100644 --- a/src/Web/Endpoints/Users.cs +++ b/src/Web/Endpoints/Users.cs @@ -24,7 +24,7 @@ public class Users : EndpointGroupBase return await sender.Send(query); } - private static async Task Login(ISender sender, LoginCommand command) + private static async Task Login(ISender sender, LoginCommand command) { return await sender.Send(command); }