prevent static optimization on root page

This commit is contained in:
Milo Schwartz 2024-10-26 21:47:12 -04:00
parent 976635e5fe
commit 4706dea3bf
No known key found for this signature in database
3 changed files with 31 additions and 37 deletions

View file

@ -46,8 +46,6 @@ export async function listOrgs(
const { limit, offset } = parsedQuery.data;
logger.debug("here0")
// Use the userOrgs passed from the middleware
const userOrgIds = req.userOrgIds;
@ -66,7 +64,6 @@ export async function listOrgs(
message: "No organizations found for the user",
status: HttpCode.OK,
});
logger.debug("here1")
}
const organizations = await db

View file

@ -24,24 +24,22 @@ export default async function RootLayout({
}>) {
const user = await verifySession();
console.log("layout.tsx user", user);
let orgs: ListOrgsResponse["orgs"] = [];
// if (user) {
// try {
// const res = await internal.get<AxiosResponse<ListOrgsResponse>>(
// `/orgs`,
// await authCookieHeader()
// );
// if (res && res.data.data.orgs) {
// orgs = res.data.data.orgs;
// }
// } catch {}
if (user) {
try {
const res = await internal.get<AxiosResponse<ListOrgsResponse>>(
`/orgs`,
await authCookieHeader()
);
if (res && res.data.data.orgs) {
orgs = res.data.data.orgs;
}
} catch {}
// if (!orgs.length) {
// redirect(`/setup`);
// }
// }
if (!orgs.length) {
redirect(`/setup`);
}
}
return (
<html suppressHydrationWarning>

View file

@ -4,34 +4,33 @@ import { verifySession } from "@app/lib/auth/verifySession";
import { LandingProvider } from "@app/providers/LandingProvider";
import { ListOrgsResponse } from "@server/routers/org";
import { AxiosResponse } from "axios";
import { ArrowUpLeft, ArrowUpRight } from "lucide-react";
import { ArrowUpRight } from "lucide-react";
import Link from "next/link";
import { redirect } from "next/navigation";
export default async function Page(props: {
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}) {
const params = await props.searchParams;
const params = await props.searchParams; // this is needed to prevent static optimization
const user = await verifySession();
console.log("page.tsx user", user);
if (!user) {
// redirect("/auth/login");
redirect("/auth/login");
return;
}
// let orgs: ListOrgsResponse["orgs"] = [];
// try {
// const res = await internal.get<AxiosResponse<ListOrgsResponse>>(
// `/orgs`,
// await authCookieHeader()
// );
// if (res && res.data.data.orgs) {
// orgs = res.data.data.orgs;
// }
// } catch (e) {}
let orgs: ListOrgsResponse["orgs"] = [];
try {
const res = await internal.get<AxiosResponse<ListOrgsResponse>>(
`/orgs`,
await authCookieHeader()
);
if (res && res.data.data.orgs) {
orgs = res.data.data.orgs;
}
} catch (e) {
console.error(e);
}
return (
<>
@ -39,7 +38,7 @@ export default async function Page(props: {
<p>Logged in as {user.email}</p>
</LandingProvider>
{/* <div className="mt-4">
<div className="mt-4">
{orgs.map((org) => (
<Link
key={org.orgId}
@ -52,7 +51,7 @@ export default async function Page(props: {
</div>
</Link>
))}
</div> */}
</div>
</>
);
}