❔ Getting Identity from [Authorize]

Hey there, since i'm using [Authorize] i thought i should be able to get UserID from var userId = HttpContext.User.FindFirstValue("nameid"); But userId keeps returning null. For context, this is how i build the claims in my AuthService
var claims = new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Sub, user.Email),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.Email, user.Email),
new Claim(JwtRegisteredClaimNames.NameId, user.Id)
}.Union(roleClaims).Union(userClaims);
var claims = new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Sub, user.Email),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.Email, user.Email),
new Claim(JwtRegisteredClaimNames.NameId, user.Id)
}.Union(roleClaims).Union(userClaims);
2 Replies
JakenVeina
JakenVeina2y ago
which one of those claims is the user ID you want?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server