Skip to content

Commit

Permalink
PAS-552 | CurrentUserCount no longer updating
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashendrickx committed Aug 4, 2024
1 parent b067f79 commit fc9dcbd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
13 changes: 9 additions & 4 deletions src/AdminConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,18 @@ async Task RunAppAsync()

builder.AddDatabase();

builder.Services.AddScoped<IPostSignInHandlerService, PostSignInHandlerService>();
builder.Services.AddTransient<IPostSignInHandlerService, PostSignInHandlerService>();
services.ConfigureApplicationCookie(o =>
{
o.Events.OnSignedIn = async context =>
o.Events.OnSignedIn = context =>
{
var handler = context.HttpContext.RequestServices.GetRequiredService<IPostSignInHandlerService>();
await handler.HandleAsync();
var organizationId = context.Principal!.GetOrgId();
if (organizationId.HasValue)
{
var postSignInHandler = context.HttpContext.RequestServices.GetRequiredService<IPostSignInHandlerService>();
return postSignInHandler.HandleAsync(organizationId.Value);
}
return Task.CompletedTask;
};
o.Cookie.Name = "AdminConsoleSignIn";
o.ExpireTimeSpan = TimeSpan.FromHours(2);
Expand Down
4 changes: 1 addition & 3 deletions src/AdminConsole/Services/IPostSignInHandlerService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Security.Claims;

namespace Passwordless.AdminConsole.Services;

public interface IPostSignInHandlerService
{
Task HandleAsync();
Task HandleAsync(int organizationId);
}
15 changes: 3 additions & 12 deletions src/AdminConsole/Services/PostSignInHandlerService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Security.Claims;
using Microsoft.EntityFrameworkCore;
using Passwordless.AdminConsole.Authorization;
using Passwordless.AdminConsole.Db;
using Passwordless.AdminConsole.Middleware;

Expand All @@ -9,28 +7,21 @@ namespace Passwordless.AdminConsole.Services;
public class PostSignInHandlerService : IPostSignInHandlerService
{
private readonly ConsoleDbContext _db;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IServiceProvider _serviceProvider;
private readonly ILogger<PostSignInHandlerService> _logger;
private readonly IServiceProvider _serviceProvider;

public PostSignInHandlerService(
ConsoleDbContext db,
IHttpContextAccessor httpContextAccessor,
IServiceProvider serviceProvider,
ILogger<PostSignInHandlerService> logger)
{
_db = db;
_httpContextAccessor = httpContextAccessor;
_serviceProvider = serviceProvider;
_logger = logger;
_serviceProvider = serviceProvider;
}

public async Task HandleAsync()
public async Task HandleAsync(int organizationId)
{
var user = _httpContextAccessor.HttpContext.User;
var organizationIdValue = user.FindFirstValue(CustomClaimTypes.OrgId);
if (organizationIdValue == null) return;
var organizationId = int.Parse(organizationIdValue);
var applications = await _db.Applications
.Where(x => x.OrganizationId == organizationId && !x.DeleteAt.HasValue)
.ToListAsync();
Expand Down

0 comments on commit fc9dcbd

Please sign in to comment.