Check if any user has logged in, and get the logged in user-core 2.1

Hello I need to check if you hear any user authentication, and after checking if any user has authenticated take the ID of that user.

I have a Middleware that redirects the user to the condominium registration screen, not letting him do anything until he registers a condominium.

The problem I have is that Middleware runs before a user even logs in.

I need to change this for it to run only after a authentication.

Middleware:

public class RedirectNoCondominium
{
    private readonly RequestDelegate _next;
    private readonly IHttpContextAccessor _httpContextAccessor;
    private readonly string path = "~/Condominium/Add";

    public RedirectNoCondominium(
        RequestDelegate next,
        IHttpContextAccessor httpContextAccessor)
    {
        _next = next;
        _httpContextAccessor = httpContextAccessor;
    }

    public async Task Invoke(HttpContext httpContext, ICondominiumService _condominiumManager)
    {

        if (user != null)
        {

            List<ApplicationCondominium> result = await _condominiumManager.GetCondominiumAsync(user);

            if (result.Count() == 0 && httpContext.Request.Path != path)
            {
                httpContext.Response.Redirect(path);
            }
            else
                await _next(httpContext);
        }
        else
        {
            await _next(httpContext);
        }

    }
}

And I call her in my startup:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {

        app.UseMiddleware<RedirectNoCondominium>();

        app.UseForwardedHeaders();

        app.Use(async (context, next) =>
        {
            if (context.Request.IsHttps || context.Request.Headers["X-Forwarded-Proto"] == Uri.UriSchemeHttps)
            {
                await next();
            }
            else
            {
                string queryString = context.Request.QueryString.HasValue ? context.Request.QueryString.Value : string.Empty;
                var https = "https://" + context.Request.Host + context.Request.Path + queryString;
                context.Response.Redirect(https);
            }
        });


        if (env.IsDevelopment())
        {

            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }


        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseCookiePolicy();

        app.UseAuthentication();

        app.UseNToastNotify();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
Author: Matheus, 2019-04-02