Add CurrentUserService to access sub from context
This commit is contained in:
@@ -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">
|
||||
|
||||
14
src/Imprink.Infrastructure/Services/CurrentUserService.cs
Normal file
14
src/Imprink.Infrastructure/Services/CurrentUserService.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user