Skip to content

Scheduling infrastructure for absolutely everyone.

fix: organizationId called on possibly undefined profile array (#17123)

Alex van Andelb1d509ba30ea
diff --git a/packages/trpc/server/routers/viewer/organizations/list.handler.ts b/packages/trpc/server/routers/viewer/organizations/list.handler.ts
index 883c6274912..e737805cbe4 100644
--- a/packages/trpc/server/routers/viewer/organizations/list.handler.ts
+++ b/packages/trpc/server/routers/viewer/organizations/list.handler.ts
@@ -11,7 +11,7 @@ type ListHandlerInput = {
// This functionality is essentially the same as the teams/list.handler.ts but it's easier for SOC to have it in a separate file.
export const listHandler = async ({ ctx }: ListHandlerInput) => {
- const organizationId = ctx.user.organization?.id ?? ctx.user.profiles[0].organizationId;
+ const organizationId = ctx.user.organization?.id ?? ctx.user.profiles[0]?.organizationId;
if (!organizationId) {
throw new TRPCError({ code: "BAD_REQUEST", message: "You do not belong to an organization" });
}