Beispiel #1
0
        public async Task <IActionResult> SignUp(LoginRequest request)
        {
            var result = await _usersService.TryInsertIfUniqueAsync(request);

            if (result == null)
            {
                return(Unauthorized("Username exists. Try another one"));
            }

            var claims    = _jwtAuthManager.GenerateClaims(result.UserId, result.UserName);
            var jwtResult = _jwtAuthManager.GenerateTokens(result.UserId, result.UserName, claims, DateTime.Now);

            result.AccessToken  = jwtResult.AccessToken;
            result.RefreshToken = jwtResult.RefreshToken.TokenString;

            return(Ok(result));
        }