Skip to content

Commit

Permalink
Move REFRESHED_USER_KEY to public const string
Browse files Browse the repository at this point in the history
Now there's a single source of truth for the two middleware classes that
need to reference it.
  • Loading branch information
rmunn committed Jul 4, 2024
1 parent a95f34f commit 79859a9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace LexBoxApi.GraphQL.CustomTypes;

public class RefreshJwtOrgMembershipMiddleware(FieldDelegate next)
{
private const string REFRESHED_USER_KEY = "RefreshedJwtMemberships";
// Should be the same value as in RefreshJwtProjectMembershipMiddleware.
public async Task InvokeAsync(IMiddlewareContext context)
{
await next(context);
Expand Down Expand Up @@ -66,12 +64,12 @@ public async Task InvokeAsync(IMiddlewareContext context)
private static async Task RefreshUser(IMiddlewareContext context, Guid userId)
{
var lexAuthService = context.Service<LexAuthService>();
context.ContextData[REFRESHED_USER_KEY] = true;
context.ContextData[GraphQlSetupKernel.RefreshedJwtMembershipsKey] = true;
await lexAuthService.RefreshUser(userId, LexAuthConstants.OrgsClaimType);
}

private static bool UserAlreadyRefreshed(IMiddlewareContext context)
{
return context.ContextData.ContainsKey(REFRESHED_USER_KEY);
return context.ContextData.ContainsKey(GraphQlSetupKernel.RefreshedJwtMembershipsKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace LexBoxApi.GraphQL.CustomTypes;

public class RefreshJwtProjectMembershipMiddleware(FieldDelegate next)
{
private const string REFRESHED_USER_KEY = "RefreshedJwtMemberships";

public async Task InvokeAsync(IMiddlewareContext context)
{
await next(context);
Expand Down Expand Up @@ -66,12 +64,12 @@ public async Task InvokeAsync(IMiddlewareContext context)
private static async Task RefreshUser(IMiddlewareContext context, Guid userId)
{
var lexAuthService = context.Service<LexAuthService>();
context.ContextData[REFRESHED_USER_KEY] = true;
context.ContextData[GraphQlSetupKernel.RefreshedJwtMembershipsKey] = true;
await lexAuthService.RefreshUser(userId, LexAuthConstants.ProjectsClaimType);
}

private static bool UserAlreadyRefreshed(IMiddlewareContext context)
{
return context.ContextData.ContainsKey(REFRESHED_USER_KEY);
return context.ContextData.ContainsKey(GraphQlSetupKernel.RefreshedJwtMembershipsKey);
}
}
1 change: 1 addition & 0 deletions backend/LexBoxApi/GraphQL/GraphQlSetupKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace LexBoxApi.GraphQL;
public static class GraphQlSetupKernel
{
public const string LexBoxSchemaName = "LexBox";
public const string RefreshedJwtMembershipsKey = "RefreshedJwtMemberships";
public static void AddLexGraphQL(this IServiceCollection services, IHostEnvironment env, bool forceGenerateSchema = false)
{
if (forceGenerateSchema || env.IsDevelopment())
Expand Down

0 comments on commit 79859a9

Please sign in to comment.