diff --git a/src/app/(main)/agency/[agencyId]/layout.tsx b/src/app/(main)/agency/[agencyId]/layout.tsx index 4bbc219..2cbdab1 100644 --- a/src/app/(main)/agency/[agencyId]/layout.tsx +++ b/src/app/(main)/agency/[agencyId]/layout.tsx @@ -1,3 +1,6 @@ +import { verifyAndAcceptInvitation } from '@/lib/queries' +import { currentUser } from '@clerk/nextjs' +import { redirect } from "next/navigation" import React from 'react' type Props = { @@ -5,10 +8,28 @@ type Props = { params: { agencyId: string } } -const layout = ({ children, params }: Props) => { - return ( -
layout
+const layout = async ({ children, params }: Props) => { + + const agencyId = await verifyAndAcceptInvitation() + const user = await currentUser() + + if (!user) { + return redirect("/") + } + + if (!agencyId) { + return redirect('/agency') + } + + if ( + user.privateMetadata.role !== 'AGENCY_OWNER' && + user.privateMetadata.role !== 'AGENCY_ADMIN' ) + // return + + return ( +
layout
+ ) } export default layout; \ No newline at end of file