mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-17 17:23:27 +02:00
check for user before getting orgs, create default config
This commit is contained in:
parent
6d9731f071
commit
717aa09daa
6 changed files with 49 additions and 29 deletions
|
@ -8,6 +8,7 @@ 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";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: `Dashboard - ${process.env.NEXT_PUBLIC_APP_NAME}`,
|
||||
|
@ -21,22 +22,26 @@ export default async function RootLayout({
|
|||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
// let orgs: ListOrgsResponse["orgs"] = [];
|
||||
// try {
|
||||
// const res = await internal.get<AxiosResponse<ListOrgsResponse>>(
|
||||
// `/orgs`,
|
||||
// authCookieHeader(),
|
||||
// );
|
||||
// if (res && res.data.data.orgs) {
|
||||
// orgs = res.data.data.orgs;
|
||||
// }
|
||||
const user = await verifySession();
|
||||
|
||||
// if (!orgs.length) {
|
||||
// redirect(`/setup`);
|
||||
// }
|
||||
// } catch (e) {
|
||||
// console.error("Error fetching orgs", e);
|
||||
// }
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<html suppressHydrationWarning>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue