using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using MyHN.Application;

namespace Website
{
  public class HttpUserProvider : IUserProvider
  {
    private readonly IHttpContextAccessor _httpContextAccessor;
    private readonly UserManager<IdentityUser> _userManager;

    public HttpUserProvider(
        IHttpContextAccessor httpContextAccessor
      , UserManager<IdentityUser> userManager)
    {
      _httpContextAccessor = httpContextAccessor;
      _userManager = userManager;
    }

    public string GetCurrentUserId()
    {
      return _userManager.GetUserId(_httpContextAccessor.HttpContext.User);
    }
  }
}