Skip to content

Commit

Permalink
[Hotfix][Duy] Return users' roles when loggin in via google
Browse files Browse the repository at this point in the history
  • Loading branch information
duykasama committed Feb 22, 2024
1 parent e2a76d7 commit e38810f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Domus.Service/Implementations/GoogleOAuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,20 @@ public async Task<ServiceActionResult> LoginAsync(OAuthRequest request)
securityToken.Claims.TryGetValue(GoogleTokenClaimConstants.PICTURE, out var picture);

var user = await _userManager.FindByEmailAsync(email) ?? await CreateNewUserAsync(email, emailVerified, name, picture);

var tokenResponse = new TokenResponse
var roles = _userManager.GetRolesAsync(user).Result.ToList();
var authResponse = new AuthResponse
{
AccessToken = _jwtService.GenerateAccessToken(user, _userManager.GetRolesAsync(user).Result.ToList()),
RefreshToken = await _jwtService.GenerateRefreshToken(user.Id),
ExpiresAt = DateTimeOffset.Now.AddHours(1)
Username = user.UserName ?? user.Email ?? string.Empty,
Roles = roles,
Token = new TokenResponse
{
AccessToken = _jwtService.GenerateAccessToken(user, roles),
RefreshToken = await _jwtService.GenerateRefreshToken(user.Id),
ExpiresAt = DateTimeOffset.Now.AddHours(1)
}
};

return new ServiceActionResult(true) { Data = tokenResponse };
return new ServiceActionResult(true) { Data = authResponse };
}

private async Task<DomusUser> CreateNewUserAsync(string email, string emailVerified, string fullName, string picture)
Expand Down

0 comments on commit e38810f

Please sign in to comment.