import getMe from "@/lib/getMe";
import hasPermissions from "@/lib/hasPermissions";
import { redirect } from "next/navigation";
import RolesAndPermissions from "./_roles";

export default async function Page() {
	const me = await getMe();
	if (
		!me ||
		me.status === "Error" ||
		!me.data ||
		!hasPermissions(me.data.roles, {
			roles: ["get"],
			permissions: ["get"],
		} as const).all
	) {
		redirect("/dashboard");
	}

	return <RolesAndPermissions user={me.data} />;
}
