-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout.tsx
More file actions
22 lines (18 loc) · 960 Bytes
/
layout.tsx
File metadata and controls
22 lines (18 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { redirect } from "next/navigation"
import { SidebarProvider } from "@/components/ui/sidebar"
import { getQueryClient, trpc } from "@/lib/trpc/server"
import { getServerSession } from "@/server/auth"
export default async function AdminLayout({ children }: { children: React.ReactNode }) {
const session = await getServerSession()
// console.log(session)
if (!session.data) redirect("/login")
const tgId = session.data.user.telegramId
if (!tgId) redirect("/onboarding/link")
// if (session?.user.role === USER_ROLE.INACTIVE) ;
// if (session?.user.role === USER_ROLE.DISABLED) redirect("/dashboard/disabled");
const qc = getQueryClient()
const { roles } = await qc.fetchQuery(trpc.tg.permissions.getRoles.queryOptions({ userId: tgId }))
if (!roles || roles.length === 0) redirect("/onboarding/no-role")
if (roles.includes("creator")) redirect("/onboarding/unauthorized")
return <SidebarProvider>{children}</SidebarProvider>
}