Skip to content

Commit afc38b5

Browse files
migrate from clerk user metadata
1 parent d8de6c2 commit afc38b5

File tree

4 files changed

+8
-26
lines changed

4 files changed

+8
-26
lines changed

apps/web/src/app/api/registration/create/route.ts

-20
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,6 @@ export async function POST(req: Request) {
3838
);
3939
}
4040

41-
if (user.publicMetadata.registrationComplete) {
42-
console.log("already registered");
43-
return NextResponse.json(
44-
{
45-
success: false,
46-
message: "You are already registered.",
47-
},
48-
{ status: 400 },
49-
);
50-
}
51-
52-
// TODO: Might be removable? Not sure if this is needed. In every case, the sure should have a piece of metadata that says if they are registered or not.
53-
5441
const lookupByUserID = await getUser(user.id);
5542

5643
if (lookupByUserID) {
@@ -129,13 +116,6 @@ export async function POST(req: Request) {
129116
});
130117
});
131118

132-
clerkClient.users.updateUser(user.id, {
133-
publicMetadata: {
134-
...user.publicMetadata,
135-
registrationComplete: true,
136-
},
137-
});
138-
139119
// sendEmail({
140120
// to: body.email,
141121
// subject: `You are now registered for ${c.hackathonName} ${c.itteration}!`,

apps/web/src/app/dash/layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface DashLayoutProps {
1919
export default async function DashLayout({ children }: DashLayoutProps) {
2020
const clerkUser = await currentUser();
2121

22-
if (!clerkUser || !clerkUser.publicMetadata.registrationComplete) {
22+
if (!clerkUser || (await getUser(clerkUser.id)) == undefined) {
2323
return redirect("/register");
2424
}
2525

apps/web/src/app/settings/layout.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import SettingsSection from "@/components/settings/SettingsSection";
55
import Navbar from "@/components/shared/Navbar";
66
import { Settings } from "lucide-react";
77
import ClientToast from "@/components/shared/ClientToast";
8+
import { getUser } from "db/functions/user";
89

910
export default async function ({ children }: { children: ReactNode }) {
1011
const { userId } = await auth();
@@ -14,7 +15,7 @@ export default async function ({ children }: { children: ReactNode }) {
1415
return redirect("/sign-in");
1516
}
1617

17-
if (!user.publicMetadata.registrationComplete) {
18+
if ((await getUser(userId)) == undefined) {
1819
return redirect("/register");
1920
}
2021

apps/web/src/components/shared/Navbar.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { auth, currentUser } from "@clerk/nextjs";
77
import NavBarLinksGrouper from "./NavBarLinksGrouper";
88
import { Oswald } from "next/font/google";
99
import { cn } from "@/lib/utils/client/cn";
10+
import { getUser } from "db/functions";
1011

1112
const oswald = Oswald({
1213
variable: "--font-oswald",
@@ -19,6 +20,8 @@ interface NavbarProps {
1920

2021
export default async function Navbar({ className }: NavbarProps) {
2122
const user = await currentUser();
23+
const registrationIsComplete =
24+
user != null && (await getUser(user.id)) != undefined;
2225
return (
2326
<div className="z-50 w-screen">
2427
<div
@@ -55,8 +58,7 @@ export default async function Navbar({ className }: NavbarProps) {
5558
<>
5659
<Link
5760
href={
58-
user.publicMetadata
59-
.registrationComplete
61+
registrationIsComplete
6062
? "/dash"
6163
: "/register"
6264
}
@@ -65,8 +67,7 @@ export default async function Navbar({ className }: NavbarProps) {
6567
variant={"outline"}
6668
className="bg-nav hover:bg-background"
6769
>
68-
{user.publicMetadata
69-
.registrationComplete
70+
{registrationIsComplete
7071
? "Dashboard"
7172
: "Complete Registration"}
7273
</Button>

0 commit comments

Comments
 (0)