using MediatR.Behaviors.Authorization; using ExpenseTracker.Application.Common.Exceptions; namespace ExpenseTracker.Application.Common.Authorization; public class MustBeAuthenticatedRequirement : IAuthorizationRequirement { public required bool IsAuthenticated { get; init; } = default!; class MustBeAuthenticatedRequirementHandler : IAuthorizationHandler { public async Task Handle(MustBeAuthenticatedRequirement request, CancellationToken cancellationToken) { if (!request.IsAuthenticated) { throw new UnAuthorizedException(); } return AuthorizationResult.Succeed(); } } }