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

@@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="14.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">

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;
}
}