Add Patch Fullname Claim
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m14s

This commit is contained in:
Leandro Hernan Rojas 2025-04-29 20:03:48 -03:00
parent 366bc0c0d3
commit bedee403b6
2 changed files with 8 additions and 40 deletions

View File

@ -238,41 +238,7 @@ namespace phronCare.API.Controllers
}
#endregion
#region GenerateAccess
//private async Task<IActionResult> GenerateAccess(ApplicationUser user)
//{
// try
// {
// var authClaims = new List<Claim>
// {
// new(ClaimTypes.Name, user.UserName),
// new(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
// };
// var userRoles = await userManager.GetRolesAsync(user);
// foreach (var role in userRoles)
// {
// authClaims.Add(new Claim(ClaimTypes.Role, role));
// }
// var jwtToken = GetToken(authClaims);
// var userSession = new UserSession
// {
// UserName = user.UserName,
// Role = userRoles.First(),
// Token = new JwtSecurityTokenHandler().WriteToken(jwtToken),
// ExpiresIn = (int)jwtToken.ValidTo.Subtract(DateTime.Now).TotalSeconds,
// ExpiryTimeStamp = jwtToken.ValidTo
// };
// return Ok(userSession);
// }
// catch (Exception ex)
// {
// return BadRequest(ex.Message);
// }
//}
#region GENERATE ACCESS:CARGA DE CLAIMS CON DATOS DEL USUARIO
private async Task<IActionResult> GenerateAccess(ApplicationUser user)
{
try
@ -280,6 +246,7 @@ namespace phronCare.API.Controllers
var authClaims = new List<Claim>
{
new(ClaimTypes.Name, user.UserName),
new("fullName", user.FullName ?? ""), // <--- ESTA ES LA LÍNEA CLAVE
new(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
};

View File

@ -1,6 +1,7 @@
<AuthorizeView>
<Authorized>
<span>Bienvenido, @context.User.Identity?.Name!</span>
<span>Bienvenido, @(context.User.FindFirst("fullName")?.Value ?? context.User.Identity?.Name)!</span>
<a href="Logout" class="btn-logout">
<i class="oi oi-account-logout"></i>
&nbsp;Cerrar sesión