B2B-30: adds personal code to account, company admins invites members
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import { isCompanyAdmin } from '../server/utils/is-company-admin';
|
||||
import { isSuperAdmin } from '@kit/admin'
|
||||
|
||||
type LayoutOrPageComponent<Params> = React.ComponentType<Params>;
|
||||
|
||||
/**
|
||||
* CompanyGuard is a server component wrapper that checks if the user is a company admin before rendering the component.
|
||||
* If the user is not a company admin, we redirect to a 404.
|
||||
* @param Component - The Page or Layout component to wrap
|
||||
*/
|
||||
export function CompanyGuard<Params extends object>(
|
||||
Component: LayoutOrPageComponent<Params>,
|
||||
) {
|
||||
return async function AdminGuardServerComponentWrapper(params: Params) {
|
||||
//@ts-ignore
|
||||
const { account } = await params.params;
|
||||
const client = getSupabaseServerClient();
|
||||
const [isUserSuperAdmin, isUserCompanyAdmin] = await Promise.all(
|
||||
[isSuperAdmin(client), isCompanyAdmin(client, account)]
|
||||
);
|
||||
|
||||
console.log({ isUserSuperAdmin, isUserCompanyAdmin , params: account})
|
||||
if (isUserSuperAdmin || isUserCompanyAdmin) {
|
||||
return <Component {...params} />;
|
||||
}
|
||||
// if the user is not a company admin, we redirect to a 404
|
||||
notFound();
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user