using System.Security.Claims;
using Microsoft.IdentityModel.JsonWebTokens;

namespace Web.Api.Extensions;

public static class ClaimsPrincipalExtensions
{
    public static int? GetMemberID(this ClaimsPrincipal user)
    {
        var memberIDClaim = user.FindFirst(JwtRegisteredClaimNames.Sub)?.Value;

        if (int.TryParse(memberIDClaim, out var memberID))
        {
            return memberID;
        }

        return null;
    }
}