Skip to content

Commit

Permalink
fix: πŸ› Unauthorized getOrganizationId(src/lib/getOrganizationId
Browse files Browse the repository at this point in the history
Page was crashed if no organization is created

βœ… Closes: #166
  • Loading branch information
growupanand committed Jan 25, 2024
1 parent 1408b9e commit f7f404d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/components/wrappers/OrganizationRequired.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { OrganizationList } from "@clerk/nextjs";

import { getOrganizationId } from "@/lib/getOrganizationId";
import { auth, OrganizationList } from "@clerk/nextjs";

type Props = {
children: React.ReactNode;
};

export const OrganizationRequired = ({ children }: Readonly<Props>) => {
const orgId = getOrganizationId();
const { orgId } = auth();

if (!orgId) {
return (
Expand Down
5 changes: 2 additions & 3 deletions src/lib/getOrganizationId.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { redirect } from "next/navigation";
import { auth } from "@clerk/nextjs";

export const getOrganizationId = () => {
const { orgId } = auth();
if (!orgId) {
const error = new Error("Organization not found");
error.name = "Unauthorized";
throw error;
redirect("/");
}
return orgId;
};

0 comments on commit f7f404d

Please sign in to comment.