- Added permission checks for creating, updating, and deleting academic terms, courses, and departments. - Updated the routes to enforce permissions for various actions in the admin panel. - Enhanced user management by adding permissions for administrators, lecturers, and students. - Refactored components to conditionally render actions based on user permissions. - Updated the auth type to include optional permissions array for user roles.
18 lines
521 B
TypeScript
18 lines
521 B
TypeScript
import { usePage } from '@inertiajs/react';
|
|
import type { Auth } from '@/types/auth';
|
|
|
|
export function usePermissions() {
|
|
const { auth } = usePage<{ auth: Auth }>().props;
|
|
const permissions = auth?.permissions ?? [];
|
|
|
|
function hasPermission(name: string): boolean {
|
|
return permissions.includes(name);
|
|
}
|
|
|
|
function hasAnyPermission(names: string[]): boolean {
|
|
return names.some((name) => permissions.includes(name));
|
|
}
|
|
|
|
return { permissions, hasPermission, hasAnyPermission };
|
|
}
|