From e4e049cb9056e758017c362a18cb6dc1750a1e93 Mon Sep 17 00:00:00 2001 From: Liam Murray Date: Sun, 21 Jul 2024 23:06:51 -0700 Subject: [PATCH] Add approval check to layout --- apps/web/src/app/dash/layout.tsx | 21 +++++++++++++++++-- apps/web/src/app/i/approval/page.tsx | 30 ++++++++++++++++++++++++++++ packages/config/hackkit.config.ts | 2 +- 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 apps/web/src/app/i/approval/page.tsx diff --git a/apps/web/src/app/dash/layout.tsx b/apps/web/src/app/dash/layout.tsx index f5d1ece7..ce6035b5 100644 --- a/apps/web/src/app/dash/layout.tsx +++ b/apps/web/src/app/dash/layout.tsx @@ -10,18 +10,35 @@ import ProfileButton from "@/components/shared/ProfileButton"; import ClientToast from "@/components/shared/ClientToast"; import { TRPCReactProvider } from "@/trpc/react"; +import { db } from "db"; +import { eq } from "db/drizzle"; +import { users } from "db/schema"; interface DashLayoutProps { children: React.ReactNode; } export default async function DashLayout({ children }: DashLayoutProps) { - const user = await currentUser(); + const clerkUser = await currentUser(); - if (!user || !user.publicMetadata.registrationComplete) { + if (!clerkUser || !clerkUser.publicMetadata.registrationComplete) { return redirect("/register"); } + const user = await db.query.users.findFirst({ + where: eq(users.clerkID, clerkUser.id), + }); + + if (!user) return redirect("/register"); + + if ( + c.featureFlags.core.requireUsersApproval === true && + user.approved === false && + user.role === "hacker" + ) { + return redirect("/i/approval"); + } + return ( <> diff --git a/apps/web/src/app/i/approval/page.tsx b/apps/web/src/app/i/approval/page.tsx new file mode 100644 index 00000000..1e082bc9 --- /dev/null +++ b/apps/web/src/app/i/approval/page.tsx @@ -0,0 +1,30 @@ +import c from "config"; +import Link from "next/link"; +import { Button } from "@/components/shadcn/ui/button"; + +export default function Page() { + return ( +
+
+

+ {c.hackathonName} +

+
+

+ {/* */} + Thanks for registering! +

+

+ Your account is awaiting approval. +
+ You will be notified when it is approved! +

+ + + +
+
+ ); +} + +export const runtime = "edge"; diff --git a/packages/config/hackkit.config.ts b/packages/config/hackkit.config.ts index 3480540d..e2bcdaaf 100644 --- a/packages/config/hackkit.config.ts +++ b/packages/config/hackkit.config.ts @@ -147,7 +147,7 @@ export default { maxTeamSize: 4, featureFlags: { core: { - requireUsersApproval: false, + requireUsersApproval: true, }, }, } as const;