public async Task InvokeAsync(HttpContext context, ICurrentUserService currentUserService) { var userIdClaim = context.User.FindFirst(e => e.Type == ClaimTypes.NameIdentifier); if (userIdClaim == null) { await _next(context); return; } await currentUserService.SetCurrentUser(int.Parse(userIdClaim.Value)); await _next(context); }
public async Task InvokeAsync(HttpContext context, ICurrentUserService currentUserService) { Claim?userIdClaim = context.User.FindFirst(e => e.Type == ClaimTypes.NameIdentifier); if (userIdClaim == null) { await _next(context); return; } if (!int.TryParse(userIdClaim.Value, out var id)) { _logger.LogError($"Could not parse user id {userIdClaim.Value} as int"); await _next(context); return; } await currentUserService.SetCurrentUser(id); await _next(context); }