fix: redirect admin/employee from home page to dashboard
This commit is contained in:
parent
76e49559e0
commit
bca26ec5e8
26
app/page.tsx
26
app/page.tsx
|
|
@ -7,9 +7,10 @@ import GrandPrize from "@/components/GrandPrize";
|
|||
import AboutContest from "@/components/AboutContest";
|
||||
import TeaIconsBackground from "@/components/TeaIconsBackground";
|
||||
import { PrizeCard } from "@/components/ui";
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useAuth } from "@/contexts/AuthContext";
|
||||
import { ROUTES } from "@/utils/constants";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
const HOME_PRIZES = [
|
||||
{ imageSrc: "/images/lots/infuseur.png", imageAlt: "Infuseur à thé premium", badge: "60%", title: "Infuseur à thé premium", description: "Un infuseur en acier inoxydable de haute qualité pour ressortir les arômes de vos thés en vrac" },
|
||||
|
|
@ -22,7 +23,28 @@ const HOME_PRIZES = [
|
|||
|
||||
export default function HomePage() {
|
||||
const [animationKey] = useState(Date.now());
|
||||
const { isAuthenticated } = useAuth();
|
||||
const { isAuthenticated, user } = useAuth();
|
||||
const router = useRouter();
|
||||
|
||||
// Redirect admin/employee to their dashboard
|
||||
useEffect(() => {
|
||||
if (isAuthenticated && user) {
|
||||
const role = user.role?.toUpperCase();
|
||||
if (role === 'ADMIN') {
|
||||
router.replace(ROUTES.ADMIN_DASHBOARD);
|
||||
} else if (role === 'EMPLOYEE') {
|
||||
router.replace(ROUTES.EMPLOYEE_DASHBOARD);
|
||||
}
|
||||
}
|
||||
}, [isAuthenticated, user, router]);
|
||||
|
||||
// Don't show home page for admin/employee
|
||||
if (isAuthenticated && user) {
|
||||
const role = user.role?.toUpperCase();
|
||||
if (role === 'ADMIN' || role === 'EMPLOYEE') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen -mt-[4.5rem] relative">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user