feat: MediaController
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace MemeVault.Api.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Scoped-сервис: идентификатор аутентифицированного пользователя из JWT.
|
||||
/// Доступен во всех контроллерах через DI.
|
||||
/// </summary>
|
||||
public sealed class CurrentUser(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
private ClaimsPrincipal Principal =>
|
||||
httpContextAccessor.HttpContext?.User
|
||||
?? throw new InvalidOperationException("No active HTTP context.");
|
||||
|
||||
public long TelegramId =>
|
||||
long.Parse(Principal.FindFirstValue(ClaimTypes.NameIdentifier)
|
||||
?? throw new InvalidOperationException("sub claim missing."));
|
||||
|
||||
public string? Username =>
|
||||
Principal.FindFirstValue(ClaimTypes.Name);
|
||||
|
||||
public bool IsAuthenticated =>
|
||||
Principal.Identity?.IsAuthenticated is true;
|
||||
}
|
||||
Reference in New Issue
Block a user