arbret/frontend/app/page.tsx

40 lines
950 B
TypeScript
Raw Permalink Normal View History

2025-12-18 21:37:28 +01:00
"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;
2025-12-18 22:24:46 +01:00
2025-12-18 21:37:28 +01:00
export default function Home() {
const { user, isLoading, hasRole } = useAuth();
const router = useRouter();
2025-12-18 23:33:32 +01:00
2025-12-18 21:37:28 +01:00
useEffect(() => {
if (isLoading) return;
2025-12-18 21:37:28 +01:00
if (!user) {
router.replace("/login");
return;
}
2025-12-18 22:08:31 +01:00
// Redirect based on role
if (hasRole(ADMIN)) {
router.replace("/admin/trades");
} else if (hasRole(REGULAR)) {
router.replace("/exchange");
} else {
// User with no roles - redirect to login
router.replace("/login");
}
}, [user, isLoading, hasRole, router]);
2025-12-18 22:08:31 +01:00
2025-12-18 21:37:28 +01:00
return (
<main style={layoutStyles.main}>
<div style={layoutStyles.loader}>Redirecting...</div>
2025-12-18 21:37:28 +01:00
</main>
);
}