Refactor user ID handling in command handlers and update Protobuf package version to 0.0.124

This commit is contained in:
masoodafar-web
2025-11-20 23:18:07 +03:30
parent 0867244888
commit 8f25757307
18 changed files with 38 additions and 22 deletions

View File

@@ -20,7 +20,7 @@ public class LoggingBehaviour : Interceptor
UnaryServerMethod<TRequest, TResponse> continuation)
{
var requestName = typeof(TRequest).Name;
var userId = _currentUserService.UserId ?? string.Empty;
var userId = _currentUserService.UserId;
_logger.LogInformation("gRPC Starting receiving call. Type/Method: {Type} / {Method} Request: {Name} {@UserId} {@Request}",
MethodType.Unary, context.Method , requestName, userId, request);

View File

@@ -33,7 +33,7 @@ public class PerformanceBehaviour : Interceptor
if (elapsedMilliseconds > 500)
{
var requestName = typeof(TRequest).Name;
var userId = _currentUserService.UserId ?? string.Empty;
var userId = _currentUserService.UserId;
_logger.LogWarning("gRPC Long Running Request: {Name} ({ElapsedMilliseconds} milliseconds) {@UserId} {@Request}",
requestName, elapsedMilliseconds, userId, request);

View File

@@ -13,7 +13,7 @@ public class CurrentUserService : ICurrentUserService
_httpContextAccessor = httpContextAccessor;
}
public string? UserId => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier);
public long? UserId => long?.Parse(_httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier) ?? throw new InvalidOperationException());
public string? FirstName => _httpContextAccessor.HttpContext?.User?.FindFirstValue("FirstName");
public string? LastName => _httpContextAccessor.HttpContext?.User?.FindFirstValue("LastName");
public string? MobileNumber => _httpContextAccessor.HttpContext?.User?.FindFirstValue("MobileNumber");