B2B-30: adds personal code to account, company admins invites members

This commit is contained in:
devmc-ee
2025-06-22 15:22:07 +03:00
parent 39c02c6d34
commit 251f2a4ef1
50 changed files with 3546 additions and 2611 deletions

View File

@@ -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();
};
}