File size: 581 Bytes
ea34bc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System.Security.Claims;

namespace SCMS.Domain.Security
{
    public static class CurrentUserExtensions
    {
        public static int? GetUserId(this ClaimsPrincipal user)
        {
            var raw = user.FindFirstValue(ClaimTypes.NameIdentifier)
                ?? user.FindFirstValue("sub");
            return int.TryParse(raw, out var userId) ? userId : null;
        }

        public static bool IsStaff(this ClaimsPrincipal user)
            => user.IsInRole("owner")
                || user.IsInRole("admin")
                || user.IsInRole("doctor");
    }
}