using WorkClub.Api.Services;

namespace WorkClub.Api.Middleware;

public class MemberSyncMiddleware
{
    private readonly RequestDelegate _next;

    public MemberSyncMiddleware(RequestDelegate next)
    {
        _next = next;
    }

    public async Task InvokeAsync(HttpContext context, MemberSyncService memberSyncService)
    {
        try
        {
            await memberSyncService.EnsureMemberExistsAsync(context);
        }
        catch
        {
        }

        await _next(context);
    }
}
