import {createDirectus, rest, readItems} from '@directus/sdk' import Container from '@mui/material/Container' import Box from '@mui/material/Box' import Typography from '@mui/material/Typography' import {auth} from '../auth.js' import Konstitisyon from '@/components/konstitisyon/index.js' import Footer from '@/components/footer.js' import Sign from '@/components/session/sign.js' import Create from '@/components/konstitisyon/create/index.js' const apiUrl = process.env.DIRECTUS_API_URL const appTitle = process.env.APP_TITLE async function getData() { if (!apiUrl) { throw new Error('DIRECTUS_API_URL is required') } const client = createDirectus(apiUrl).with(rest()) try { const titres = await client.request( readItems('titres', { filter: { status: { _eq: 'published' } }, sort: 'numero' }) ) const articles = await client.request( readItems('articles', { filter: { status: { _eq: 'published' } }, sort: 'numero' }) ) if (titres.length === 0 || articles.length === 0) { throw new Error('No data') } return { titres, articles } } catch { throw new Error('Failed to fetch data') } } export default async function Page() { const session = await auth() const {titres, articles} = await getData() return ( {appTitle.toUpperCase()} {session && ( )}