19 lines
No EOL
567 B
C#
19 lines
No EOL
567 B
C#
using System.Security.Claims;
|
|
using SurveyBackend.Core.Contexts;
|
|
|
|
namespace SurveyBackend.Contexts;
|
|
|
|
public class UserContext : IUserContext
|
|
{
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
public UserContext(IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
_httpContextAccessor = httpContextAccessor;
|
|
}
|
|
|
|
public int UserId =>
|
|
int.Parse(
|
|
_httpContextAccessor.HttpContext?.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)
|
|
?.Value ?? throw new UnauthorizedAccessException());
|
|
} |