diff --git a/URL-Shortener/Controllers/UserController.cs b/URL-Shortener/Controllers/UserController.cs index 30206bb..3062254 100644 --- a/URL-Shortener/Controllers/UserController.cs +++ b/URL-Shortener/Controllers/UserController.cs @@ -13,8 +13,8 @@ namespace URL_Shortener.Controllers [HttpPost("register")] public async Task RegisterAsync(RegisterUserDTO dto) { - await _userService.RegisterAsync(dto.Name, dto.Email, dto.Password); - return Ok(); + var jwt = await _userService.RegisterAsync(dto.Name, dto.Email, dto.Password); + return Ok(jwt); } [HttpPost("login")] diff --git a/URL-Shortener/Services/UserService.cs b/URL-Shortener/Services/UserService.cs index 9db36d0..0e47540 100644 --- a/URL-Shortener/Services/UserService.cs +++ b/URL-Shortener/Services/UserService.cs @@ -9,7 +9,7 @@ namespace URL_Shortener.Services private readonly AppDbContext _db = db; private readonly JwtService _jwtService = jwtService; - public async Task RegisterAsync(string userName, string email, string password, CancellationToken cancellationToken = default) + public async Task RegisterAsync(string userName, string email, string password, CancellationToken cancellationToken = default) { if (await _db.Users.FirstOrDefaultAsync(u => u.Email == email, cancellationToken) != null) throw new Exception("This user already exists."); @@ -23,6 +23,8 @@ namespace URL_Shortener.Services await _db.Users.AddAsync(user, cancellationToken); await _db.SaveChangesAsync(cancellationToken); + + return _jwtService.GenerateToken(user); } public async Task LoginAsync(string email, string password, CancellationToken cancellationToken = default)