Add CurrentUserService to access sub from context

This commit is contained in:
lumijiez
2025-06-11 00:01:50 +03:00
parent d4978dff15
commit 6a7bef80d0
7 changed files with 60 additions and 1 deletions

View File

@@ -0,0 +1,14 @@
using System.Security.Claims;
using Imprink.Application.Service;
using Microsoft.AspNetCore.Http;
namespace Imprink.Infrastructure.Services;
public class CurrentUserService(IHttpContextAccessor httpContextAccessor) : ICurrentUserService
{
public string? GetCurrentUserId()
{
return httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value
?? httpContextAccessor.HttpContext?.User?.FindFirst("sub")?.Value;
}
}