- Delete pages: sum, audit, admin/random-jobs - Delete old homepage (counter) and create redirect page - Update Header.tsx: remove Counter, Sum, Audit, Random Jobs nav items - Update auth-context.tsx: remove VIEW_COUNTER, INCREMENT_COUNTER, USE_SUM permissions - Update profile/page.test.tsx: fix nav link assertions
39 lines
955 B
TypeScript
39 lines
955 B
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useAuth } from "./auth-context";
|
|
import { layoutStyles } from "./styles/shared";
|
|
import constants from "../../shared/constants.json";
|
|
|
|
const { ADMIN, REGULAR } = constants.roles;
|
|
|
|
export default function Home() {
|
|
const { user, isLoading, hasRole } = useAuth();
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
if (isLoading) return;
|
|
|
|
if (!user) {
|
|
router.replace("/login");
|
|
return;
|
|
}
|
|
|
|
// Redirect based on role
|
|
if (hasRole(ADMIN)) {
|
|
router.replace("/admin/appointments");
|
|
} else if (hasRole(REGULAR)) {
|
|
router.replace("/booking");
|
|
} else {
|
|
// User with no roles - redirect to login
|
|
router.replace("/login");
|
|
}
|
|
}, [user, isLoading, hasRole, router]);
|
|
|
|
return (
|
|
<main style={layoutStyles.main}>
|
|
<div style={layoutStyles.loader}>Redirecting...</div>
|
|
</main>
|
|
);
|
|
}
|