feat: can only access own's project edit page

This commit is contained in:
Sosokker 2024-11-07 15:51:04 +07:00
parent 8a826e0b90
commit 578cff2507

View File

@ -4,11 +4,26 @@ import { Separator } from "@/components/ui/separator";
import { getProjectDataQuery } from "@/lib/data/projectQuery";
import { createSupabaseClient } from "@/lib/supabase/serverComponentClient";
import { ProjectEditSchema } from "@/types/schemas/project.schema";
import { redirect } from "next/navigation";
export default async function EditProjectPage({ params }: { params: { projectId: string } }) {
const client = createSupabaseClient();
const projectId = Number(params.projectId);
// Check permission
const { data: user, error: userError } = await client.auth.getUser();
const uuid = user.user?.id;
const { data, error } = await client.from("project").select("...business(user_id)").eq("id", projectId).single();
console.log(uuid);
console.log(data);
if (userError || error) {
redirect("/");
}
if (data.user_id != uuid || data == null) {
redirect("/");
}
const { data: projectData, error: projectDataError } = await getProjectDataQuery(client, projectId);
if (projectDataError) {