Authentication
💡
This documentation covers an older version of Next Admin. If you are using the
latest version (>=5.0.0
and above), please refer to the current
documentation.
The library does not provide an authentication system. If you want to add your own, you can do so by adding a role check in the page:
The following example uses next-auth (opens in a new tab) to handle authentication
app/admin/[[...nextadmin]]/page.tsx
export default async function AdminPage({
params,
searchParams,
}: {
params: { [key: string]: string[] };
searchParams: { [key: string]: string | string[] | undefined } | undefined;
}) {
const session = await getServerSession(authOptions);
const isAdmin = session?.user?.role === "SUPERADMIN"; // your role check
if (!isAdmin) {
redirect('/', { permanent: false })
}
const props = await getPropsFromParams({
params: params.nextadmin,
searchParams,
options,
prisma,
schema,
action: submitFormAction,
});
return <NextAdmin {...props} dashboard={Dashboard} />;
}