Skip to content

Commit

Permalink
migrate from clerk user metadata (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhelp authored Sep 24, 2024
1 parent 8cbd1b0 commit b96f742
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
20 changes: 0 additions & 20 deletions apps/web/src/app/api/registration/create/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ export async function POST(req: Request) {
);
}

if (user.publicMetadata.registrationComplete) {
console.log("already registered");
return NextResponse.json(
{
success: false,
message: "You are already registered.",
},
{ status: 400 },
);
}

// 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.

const lookupByUserID = await getUser(user.id);

if (lookupByUserID) {
Expand Down Expand Up @@ -129,13 +116,6 @@ export async function POST(req: Request) {
});
});

await clerkClient.users.updateUser(user.id, {
publicMetadata: {
...user.publicMetadata,
registrationComplete: true,
},
});

// sendEmail({
// to: body.email,
// subject: `You are now registered for ${c.hackathonName} ${c.itteration}!`,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/dash/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface DashLayoutProps {
export default async function DashLayout({ children }: DashLayoutProps) {
const clerkUser = await currentUser();

if (!clerkUser || !clerkUser.publicMetadata.registrationComplete) {
if (!clerkUser || (await getUser(clerkUser.id)) == undefined) {
return redirect("/register");
}

Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/app/settings/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SettingsSection from "@/components/settings/SettingsSection";
import Navbar from "@/components/shared/Navbar";
import { Settings } from "lucide-react";
import ClientToast from "@/components/shared/ClientToast";
import { getUser } from "db/functions/user";

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

if (!user.publicMetadata.registrationComplete) {
if ((await getUser(userId)) == undefined) {
return redirect("/register");
}

Expand Down
9 changes: 5 additions & 4 deletions apps/web/src/components/shared/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { auth, currentUser } from "@clerk/nextjs";
import NavBarLinksGrouper from "./NavBarLinksGrouper";
import { Open_Sans } from "next/font/google";
import { cn } from "@/lib/utils/client/cn";
import { getUser } from "db/functions";

const openSans = Open_Sans({
variable: "--font-open-sans",
Expand All @@ -19,6 +20,8 @@ interface NavbarProps {

export default async function Navbar({ className }: NavbarProps) {
const user = await currentUser();
const registrationIsComplete =
user != null && (await getUser(user.id)) != undefined;
return (
<div className="z-50 w-screen">
<div
Expand Down Expand Up @@ -57,8 +60,7 @@ export default async function Navbar({ className }: NavbarProps) {
<>
<Link
href={
user.publicMetadata
.registrationComplete
registrationIsComplete
? "/dash"
: "/register"
}
Expand All @@ -67,8 +69,7 @@ export default async function Navbar({ className }: NavbarProps) {
variant={"outline"}
className="bg-nav hover:bg-background"
>
{user.publicMetadata
.registrationComplete
{registrationIsComplete
? "Dashboard"
: "Complete Registration"}
</Button>
Expand Down

0 comments on commit b96f742

Please sign in to comment.