Skip to content

Commit

Permalink
StateShape
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan committed Dec 13, 2023
1 parent ab3c0dc commit 5105fbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Koa from "koa";
import * as Constants from "./constants";
import * as Utils from "./utils";
import UserManagementService from "./service";
import { Permission } from "./type";
import { StateShape, Permission } from "./type";

export const isAuthenticatedNonMiddleware =
(userManagement: UserManagementService) => async (ctx: Koa.Context) => {
Expand Down Expand Up @@ -35,7 +35,9 @@ export const isAuthenticatedNonMiddleware =
ctx.cookies.set(Constants.cookieValues.accessToken, newAccessToken);
}

ctx.state = { id, email, instanceId, permissions };
const ctxState: StateShape = { id, email, instanceId, permissions };

ctx.state = ctxState;
};

export const isAuthenticated =
Expand Down
5 changes: 5 additions & 0 deletions src/lib/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,8 @@ export interface UserAuthentication {
isEnabled: boolean;
type: AuthenticationType;
}

export type StateShape = Pick<
TokenShape,
"id" | "email" | "instanceId" | "permissions"
>;

0 comments on commit 5105fbd

Please sign in to comment.