false, 'message' => 'Unauthorized']); exit; } /** * Check if user has a specific role. */ public static function requireRole(string $role): void { self::requireAuth(); $user = Auth::user(); if (!$user || $user['role'] !== $role) { // Or redirect to a "403 Forbidden" page header('Location: /'); exit; } } /** * Check if user has admin role. */ public static function requireAdmin(): void { self::requireRole('admin'); } /** * If user is already logged in, redirect them from login/register pages. */ public static function redirectIfAuthenticated(): void { if (Auth::check()) { header('Location: /apps/users/profile'); // Redirect to profile or dashboard exit(); } } public function requireGuest(): void { if (Auth::check()) { header('Location: /apps/users/profile'); // Redirect to profile or dashboard exit(); } } }