Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(api): resolve the viewer in invitation hooks

Andrej376ef7fe7cf8
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts
index e55f3d443..16e9d872e 100644
--- a/apps/api/src/auth.ts
+++ b/apps/api/src/auth.ts
@@ -908,19 +908,20 @@ export const auth = betterAuth({
}
}),
after: createAuthMiddleware(async (ctx) => {
- const viewerId = ctx.context.session?.user.id;
- if (viewerId && ctx.path === "/organization/list-invitations") {
- await hideInaccessibleInvitationProjects(
- viewerId,
- ctx.context.returned,
- );
- }
- if (viewerId && ctx.path === "/organization/get-full-organization") {
- await hideInaccessibleInvitationProjects(
- viewerId,
- (ctx.context.returned as { invitations?: unknown } | null)
- ?.invitations,
- );
+ if (
+ ctx.path === "/organization/list-invitations" ||
+ ctx.path === "/organization/get-full-organization"
+ ) {
+ const viewer = await getSessionFromCtx(ctx);
+ const returned = ctx.context.returned as
+ | { invitations?: unknown }
+ | unknown[]
+ | null;
+ if (viewer)
+ await hideInaccessibleInvitationProjects(
+ viewer.user.id,
+ Array.isArray(returned) ? returned : returned?.invitations,
+ );
}
if (ctx.path === "/organization/leave") {