2024-04-16 16:25:21 -04:00
|
|
|
import Dashboard from "@/components/dashboard"
|
|
|
|
import Navbar from "@/components/dashboard/navbar"
|
2024-10-21 13:57:45 -06:00
|
|
|
import { User } from "@/lib/types"
|
|
|
|
import { currentUser } from "@clerk/nextjs"
|
|
|
|
import { redirect } from "next/navigation"
|
2024-04-16 16:25:21 -04:00
|
|
|
|
|
|
|
export default async function DashboardPage() {
|
|
|
|
const user = await currentUser()
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
redirect("/")
|
|
|
|
}
|
|
|
|
|
2024-05-05 22:33:24 -07:00
|
|
|
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-05-05 22:33:24 -07:00
|
|
|
)
|
2024-04-18 15:25:20 -04:00
|
|
|
const userData = (await userRes.json()) as User
|
2024-04-18 00:13:40 -04:00
|
|
|
|
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-11-10 23:40:10 -05:00
|
|
|
authorAvatarUrl: string
|
2024-05-01 02:49:25 -04:00
|
|
|
}[]
|
|
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|