fosrl.pangolin/src/app/layout.tsx

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-09-27 19:48:49 -04:00
import type { Metadata } from "next";
import "./globals.css";
2024-10-19 16:37:40 -04:00
import { Inter } from "next/font/google";
2024-10-14 12:10:02 -04:00
import { Toaster } from "@/components/ui/toaster";
2024-10-14 18:26:07 -04:00
import { ThemeProvider } from "@app/providers/ThemeProvider";
2024-10-19 16:37:40 -04:00
import { ListOrgsResponse } from "@server/routers/org";
import { internal } from "@app/api";
import { AxiosResponse } from "axios";
import { authCookieHeader } from "@app/api/cookies";
import { redirect } from "next/navigation";
import { verifySession } from "@app/lib/auth/verifySession";
2024-09-27 19:48:49 -04:00
export const metadata: Metadata = {
2024-10-19 17:05:54 -04:00
title: `Dashboard - ${process.env.NEXT_PUBLIC_APP_NAME}`,
2024-09-27 21:39:03 -04:00
description: "",
2024-09-27 19:48:49 -04:00
};
2024-10-17 22:12:02 -04:00
const font = Inter({ subsets: ["latin"] });
2024-10-06 11:13:50 -04:00
export default async function RootLayout({
2024-09-27 21:39:03 -04:00
children,
2024-09-27 19:48:49 -04:00
}: Readonly<{
2024-09-27 21:39:03 -04:00
children: React.ReactNode;
2024-09-27 19:48:49 -04:00
}>) {
const user = await verifySession();
2024-10-19 16:37:40 -04:00
let orgs: ListOrgsResponse["orgs"] = [];
if (user) {
try {
const res = await internal.get<AxiosResponse<ListOrgsResponse>>(
`/orgs`,
authCookieHeader(),
);
if (res && res.data.data.orgs) {
orgs = res.data.data.orgs;
}
if (!orgs.length) {
redirect(`/setup`);
}
} catch (e) {
console.error("Error fetching orgs", e);
}
}
2024-10-19 16:37:40 -04:00
2024-09-27 21:39:03 -04:00
return (
2024-10-14 18:26:07 -04:00
<html suppressHydrationWarning>
2024-10-14 12:10:02 -04:00
<body className={`${font.className} pb-3`}>
2024-10-14 18:26:07 -04:00
<ThemeProvider
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
>
{children}
<Toaster />
</ThemeProvider>
2024-10-06 11:13:50 -04:00
</body>
2024-09-27 21:39:03 -04:00
</html>
);
2024-09-27 19:48:49 -04:00
}