using Hangfire.Dashboard;

namespace BimAI.API.Services;

public class HangfireAuthorizationFilter: IDashboardAsyncAuthorizationFilter
{
    public Task<bool> AuthorizeAsync(DashboardContext context)
    {
        var httpContext = context.GetHttpContext();
        
        var env = httpContext.RequestServices.GetService<IWebHostEnvironment>();
        if (env.IsDevelopment())
        {
            return Task.FromResult(true);
        }
        
        var isAuthenticated =  httpContext.User.Identity?.IsAuthenticated ?? false;
        return Task.FromResult(isAuthenticated);
    }
}