From 130a4932e646b39a2df045c25ca002f44f975b72 Mon Sep 17 00:00:00 2001
From: Bart van der Braak <bartvdbraak@gmail.com>
Date: Thu, 8 Jun 2023 00:38:36 +0200
Subject: [PATCH] feat: Auth library for Tenant and User ID

---
 lib/auth.ts | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 lib/auth.ts

diff --git a/lib/auth.ts b/lib/auth.ts
new file mode 100644
index 0000000..4a8cd95
--- /dev/null
+++ b/lib/auth.ts
@@ -0,0 +1,12 @@
+import { auth } from "@clerk/nextjs/app-beta";
+import { notFound } from "next/navigation";
+
+/**
+ * Return the tenant id or a 404 not found page.
+ *
+ * The auth check should already be done at a higher level, and we're just returning 404 to make typescript happy.
+ */
+export function getTenantId(): string {
+  const { userId, orgId } = auth();
+  return orgId ?? userId ?? notFound();
+}