47 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

2024-04-16 16:25:21 -04:00
import { UserButton, currentUser } from "@clerk/nextjs"
import { redirect } from "next/navigation"
import Dashboard from "@/components/dashboard"
import Navbar from "@/components/dashboard/navbar"
2024-04-18 15:25:20 -04:00
import { Sandbox, User } from "@/lib/types"
2024-04-16 16:25:21 -04:00
export default async function DashboardPage() {
const user = await currentUser()
if (!user) {
redirect("/")
}
const userRes = await fetch(
2024-05-26 18:37:36 -07:00
`${process.env.NEXT_PUBLIC_DATABASE_WORKER_URL}/api/user?id=${user.id}`,
{
headers: {
Authorization: `${process.env.NEXT_PUBLIC_WORKERS_KEY}`,
},
}
)
2024-04-18 15:25:20 -04:00
const userData = (await userRes.json()) as User
2024-05-01 02:49:25 -04:00
const sharedRes = await fetch(
2024-05-26 18:37:36 -07:00
`${process.env.NEXT_PUBLIC_DATABASE_WORKER_URL}/api/sandbox/share?id=${user.id}`,
{
headers: {
Authorization: `${process.env.NEXT_PUBLIC_WORKERS_KEY}`,
},
}
2024-05-01 02:49:25 -04:00
)
const shared = (await sharedRes.json()) as {
id: string
name: string
type: "react" | "node"
author: string
sharedOn: Date
}[]
2024-04-16 16:25:21 -04:00
return (
<div className="w-screen h-screen flex flex-col overflow-hidden overscroll-none">
2024-04-18 15:25:20 -04:00
<Navbar userData={userData} />
2024-05-01 02:49:25 -04:00
<Dashboard sandboxes={userData.sandbox} shared={shared} />
2024-04-16 16:25:21 -04:00
</div>
)
}