From f2343acb702b64224bd8f4f930e8531b9fe779b5 Mon Sep 17 00:00:00 2001
From: Brandon Egger <brandonegger64@gmail.com>
Date: Mon, 22 May 2023 23:14:37 -0500
Subject: [PATCH] conditionally render the admin bar based on role rather than
 just if they are signed in

---
 src/components/admin/ControlBar.tsx | 3 ++-
 src/server/auth.ts                  | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/components/admin/ControlBar.tsx b/src/components/admin/ControlBar.tsx
index 46818d9..5b70a5e 100644
--- a/src/components/admin/ControlBar.tsx
+++ b/src/components/admin/ControlBar.tsx
@@ -1,3 +1,4 @@
+import { Role } from "@prisma/client";
 import { useSession } from "next-auth/react";
 
 const AdminBarLayout = ({
@@ -11,7 +12,7 @@ const AdminBarLayout = ({
 
   return (
     <div className="relative">
-      {data?.user ? (
+      {data?.user.role === Role.ADMIN ? (
         <div className="sticky left-0 right-0 top-[71px] z-10 mx-auto mb-6 mt-[15px] flex max-w-4xl flex-row justify-between rounded-xl border border-neutral-600 bg-red-300 drop-shadow-xl">
           <h1 className="rounded-lg px-4 py-2 font-semibold text-black">
             Admin Mode
diff --git a/src/server/auth.ts b/src/server/auth.ts
index 533768c..54426d0 100644
--- a/src/server/auth.ts
+++ b/src/server/auth.ts
@@ -9,11 +9,13 @@ import { PrismaAdapter } from "@next-auth/prisma-adapter";
 import { prisma } from "~/server/db";
 import { loginSchema } from "~/lib/validation/auth";
 import { verify } from "argon2";
+import { type Role } from "@prisma/client";
 
 interface SessionUser {
   id: string;
   name: string;
   username: string;
+  role: Role;
 }
 
 /**
@@ -100,6 +102,7 @@ export const authOptions: NextAuthOptions = {
             id: result.id,
             name: result.name,
             username,
+            role: result.role,
           };
         } catch {
           return null;