Wrap admin pages with AdminGuard component
The AdminGuard component has been added to the AccountPage, AccountsPage, and AdminPage in the web app. This server-side implementation ensures that these pages are only accessible to super-admin users. If a user is not a super-admin, the guard will trigger a redirect to a 404 page.
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
export default function AccountPage() {
|
import { AdminGuard } from '@kit/admin/components/admin-guard';
|
||||||
|
|
||||||
|
function AccountPage() {
|
||||||
return <div></div>;
|
return <div></div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default AdminGuard(AccountPage);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import { AdminGuard } from '@kit/admin/components/admin-guard';
|
||||||
import { PageBody, PageHeader } from '@kit/ui/page';
|
import { PageBody, PageHeader } from '@kit/ui/page';
|
||||||
|
|
||||||
export default function AccountsPage() {
|
function AccountsPage() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader title={'Accounts'} />
|
<PageHeader title={'Accounts'} />
|
||||||
@@ -8,3 +9,5 @@ export default function AccountsPage() {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default AdminGuard(AccountsPage);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { AdminDashboard } from '@kit/admin/components/admin-dashboard';
|
import { AdminDashboard } from '@kit/admin/components/admin-dashboard';
|
||||||
|
import { AdminGuard } from '@kit/admin/components/admin-guard';
|
||||||
import { PageBody, PageHeader } from '@kit/ui/page';
|
import { PageBody, PageHeader } from '@kit/ui/page';
|
||||||
|
|
||||||
export default function AdminPage() {
|
function AdminPage() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader title={'Admin'} description={`Your SaaS stats at a glance`} />
|
<PageHeader title={'Admin'} description={`Your SaaS stats at a glance`} />
|
||||||
@@ -12,3 +13,5 @@ export default function AdminPage() {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default AdminGuard(AdminPage);
|
||||||
|
|||||||
@@ -2,10 +2,15 @@ import { notFound } from 'next/navigation';
|
|||||||
|
|
||||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||||
|
|
||||||
import { isSuperAdmin } from '../lib/is-super-admin';
|
import { isSuperAdmin } from '../lib/server/is-super-admin';
|
||||||
|
|
||||||
type LayoutOrPageComponent<Params> = React.ComponentType<Params>;
|
type LayoutOrPageComponent<Params> = React.ComponentType<Params>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AdminGuard is a server component wrapper that checks if the user is a super-admin before rendering the component.
|
||||||
|
* If the user is not a super-admin, we redirect to a 404.
|
||||||
|
* @param Component - The Page or Layout component to wrap
|
||||||
|
*/
|
||||||
export function AdminGuard<Params extends object>(
|
export function AdminGuard<Params extends object>(
|
||||||
Component: LayoutOrPageComponent<Params>,
|
Component: LayoutOrPageComponent<Params>,
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user