"use client"; import { Divider, Stack, Text } from '@mantine/core'; import { usePathname } from 'next/navigation'; import Link from 'next/link'; import React, { useEffect, useState } from 'react'; import { useRouter } from "next/navigation"; export default function Layout({ children }: { children: React.ReactNode }) { const [authorized, SetAuthorized] = useState(null); const router = useRouter(); const pathname = usePathname(); const links = [ { label: "Account Summary", href: "/accounts" }, { label: "Statement of Account", href: "/accounts/account_statement" }, { label: "Account Details", href: "/accounts/account_details" }, ]; useEffect(() => { const token = localStorage.getItem("access_token"); if (!token) { SetAuthorized(false); router.push("/login"); } else { SetAuthorized(true); } }, []); if (authorized) { return (
Accounts {links.map(link => { const isActive = pathname === link.href; return ( {link.label} ); })}
{children}
); } }