T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/lavocat.ca/private_html/src/pages/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.ca/private_html/src/pages/dashboard.tsx
import { useEffect, useState } from 'react';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/router';
import LayoutWithSidebar from '../components/LayoutWithSidebar';
import { 
  Loader2, 
  User, 
  Building, 
  Scale, 
  Users, 
  Shield, 
  AlertTriangle 
} from 'lucide-react';

export default function Dashboard() {
  const { data: session, status } = useSession();
  const router = useRouter();
  const [redirectAttempted, setRedirectAttempted] = useState(false);

  useEffect(() => {
    console.log('Dashboard useEffect triggered:', { status, session: !!session, role: session?.user?.role, redirectAttempted });
    
    // Prevent infinite redirects
    if (redirectAttempted) {
      console.log('Redirect already attempted, skipping');
      return;
    }
    
    if (status === 'loading') {
      console.log('Still loading session...');
      return;
    }

    if (!session) {
      console.log('No session, redirecting to signin');
      router.push('/auth/login');
      return;
    }

    // Set flag to prevent infinite redirects
    setRedirectAttempted(true);

    // Route users to their role-specific dashboard
    const role = session.user.role;
    console.log('User role:', role);
    
    let targetRoute = '/user/dashboard'; // default
    
    switch (role) {
      case 'ADMIN':
      case 'SUPERADMIN':
      case 'SUPERADMIN':
      case 'SUPERADMIN':
      case 'SUPERADMIN':
        targetRoute = '/admin/dashboard';
        break;
      case 'LAWYER':
        targetRoute = '/lawyer/dashboard';
        break;
      case 'JURIST':
        targetRoute = '/jurist/dashboard';
        break;
      case 'JUDGE':
        targetRoute = '/judge/dashboard';
        break;
      case 'MEDIATOR':
        targetRoute = '/mediator/dashboard';
        break;
      case 'LEGAL_CONSULTANT':
        targetRoute = '/consultant/dashboard';
        break;
      case 'INVESTIGATOR':
        targetRoute = '/investigator/dashboard';
        break;
      case 'EXPERT_WITNESS':
        targetRoute = '/expert/dashboard';
        break;
      case 'SUPPORT_STAFF':
      case 'SECRETARY':
      case 'ASSISTANT':
      case 'CLERK':
      case 'COURT_CLERK':
      case 'PARALEGAL':
        targetRoute = '/support/dashboard';
        break;
      case 'STUDENT':
        targetRoute = '/student/dashboard';
        break;
      case 'NOTARY':
        targetRoute = '/notary/dashboard';
        break;
      case 'CLIENT':
      case 'USER':
      default:
        targetRoute = '/user/dashboard';
        break;
    }
    
    console.log('Redirecting to:', targetRoute);
    
    // Add a small delay to prevent immediate redirect
    setTimeout(() => {
      router.push(targetRoute);
    }, 1000);
  }, [session, status, router, redirectAttempted]);

  if (status === 'loading') {
    return (
      <LayoutWithSidebar>
        <div className="min-h-screen flex items-center justify-center">
          <div className="text-center">
            <Loader2 className="h-8 w-8 animate-spin mx-auto mb-4 text-blue-600" />
            <h2 className="text-xl font-semibold text-gray-900 mb-2">Loading Dashboard</h2>
            <p className="text-gray-600">Redirecting to your personalized dashboard...</p>
          </div>
        </div>
      </LayoutWithSidebar>
    );
  }

  if (!session) {
    return (
      <LayoutWithSidebar>
        <div className="min-h-screen flex items-center justify-center">
          <div className="text-center">
            <AlertTriangle className="h-8 w-8 mx-auto mb-4 text-red-600" />
            <h2 className="text-xl font-semibold text-gray-900 mb-2">Authentication Required</h2>
            <p className="text-gray-600 mb-4">Please sign in to access your dashboard.</p>
            <button
              onClick={() => router.push('/auth/login')}
              className="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors"
            >
              Sign In
            </button>
          </div>
        </div>
      </LayoutWithSidebar>
    );
  }

  // Fallback loading state while redirecting
  return (
    <LayoutWithSidebar>
      <div className="min-h-screen flex items-center justify-center">
        <div className="text-center">
          <div className="flex items-center justify-center mb-4">
            {session.user.role === 'ADMIN' || session.user.role === 'SUPERADMIN' || session.user.role === 'SUPERADMIN' ? (
              <Shield className="h-8 w-8 text-red-600" />
            ) : session.user.role === 'LAWYER' ? (
              <Scale className="h-8 w-8 text-blue-600" />
            ) : session.user.role === 'JUDGE' ? (
              <Building className="h-8 w-8 text-purple-600" />
            ) : session.user.role === 'MEDIATOR' ? (
              <Users className="h-8 w-8 text-green-600" />
            ) : (
              <User className="h-8 w-8 text-gray-600" />
            )}
          </div>
          <h2 className="text-xl font-semibold text-gray-900 mb-2">
            Welcome, {session.user.name}!
          </h2>
          <p className="text-gray-600 mb-4">
            Redirecting to your {session.user.role.toLowerCase().replace('_', ' ')} dashboard...
          </p>
          <Loader2 className="h-6 w-6 animate-spin mx-auto text-blue-600" />
        </div>
      </div>
    </LayoutWithSidebar>
  );
} 

CasperSecurity Mini