Add CurrentUserService to access sub from context
This commit is contained in:
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