using System.Security.Claims;
using JobsMedical.Web.Models;
using Microsoft.AspNetCore.Authentication.Cookies;
namespace JobsMedical.Web.Services;
/// Builds the cookie principal for a user. Shared by login and by role changes
/// (e.g. when a user registers a facility and becomes a FacilityAdmin mid-session).
public static class AuthHelper
{
public static ClaimsPrincipal BuildPrincipal(User user)
{
var claims = new List
{
new(ClaimTypes.NameIdentifier, user.Id.ToString()),
new(ClaimTypes.MobilePhone, user.Phone),
new(ClaimTypes.Name, user.FullName ?? user.Phone),
new(ClaimTypes.Role, user.Role.ToString()),
};
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
return new ClaimsPrincipal(identity);
}
}