Added few configurations & mores
This commit is contained in:
27
lib/withPageAccess.tsx
Normal file
27
lib/withPageAccess.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
import { getCurrentUser } from '@/lib/auth';
|
||||
import { hasPageAccess } from '@/lib/permissions';
|
||||
|
||||
/**
|
||||
* HOC pour protéger une page avec vérification des permissions
|
||||
*/
|
||||
export async function withPageAccess(
|
||||
pageRoute: string,
|
||||
PageComponent: React.ComponentType<any>
|
||||
) {
|
||||
return async function ProtectedPage(props: any) {
|
||||
const user = await getCurrentUser();
|
||||
|
||||
if (!user) {
|
||||
redirect('/login');
|
||||
}
|
||||
|
||||
const hasAccess = await hasPageAccess(user.id, pageRoute);
|
||||
if (!hasAccess) {
|
||||
// Rediriger vers la première page accessible ou paramètres
|
||||
redirect('/dashboard/parametres');
|
||||
}
|
||||
|
||||
return <PageComponent {...props} />;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user