Spaces:
Running
Running
File size: 1,077 Bytes
1cf8f01 eecbedf 1cf8f01 eecbedf 1cf8f01 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import { apiServer } from "@/lib/api";
import MY_TOKEN_KEY from "@/lib/get-cookie-name";
import { AppEditor } from "@/components/editor";
async function getProject(namespace: string, repoId: string) {
// TODO replace with a server action
const cookieStore = await cookies();
const token = cookieStore.get(MY_TOKEN_KEY())?.value;
if (!token) return {};
try {
const { data } = await apiServer.get(
`/me/projects/${namespace}/${repoId}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
return data.project;
} catch {
return {};
}
}
export default async function ProjectNamespacePage({
params,
}: {
params: Promise<{ namespace: string; repoId: string }>;
}) {
const { namespace, repoId } = await params;
const data = await getProject(namespace, repoId);
if (!data?.pages) {
redirect("/projects");
}
return (
<AppEditor project={data} pages={data.pages} images={data.images ?? []} />
);
}
|