I use Auth0
for authentication and authorization with the backend .Net core
for frontend React applications. I am trying to get the logged-in user Id or email using httpContextaccessor in the API
for logging purposes. But getting the value like this auth|374634....
. Below is the code for the same. I am unsure whether I consider this an Id after this part auth|
public interface IUserIdProvider
{
string? GetUserId();
}
public class UserIdProvider : IUserIdProvider
{
private readonly IHttpContextAccessor _httpContextAccessor;
public UserIdProvider(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public string GetUserId()
{
var userId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
return userId ?? string.Empty;
}
}
I get the information below when I watch the info near userId
Please let me know how to get the logged-in user id or user email in API.
Many thanks in advance!!!