dont import db in nextjs

This commit is contained in:
miloschwartz
2025-06-05 14:43:47 -04:00
parent b6f67e0f0b
commit f0cb65f65c
9 changed files with 13838 additions and 15982 deletions

View File

@@ -1,8 +1,11 @@
import { cookies } from "next/headers";
import ValidateOidcToken from "./ValidateOidcToken";
import { idp } from "@server/db";
import { db } from "@server/db";
import { eq } from "drizzle-orm";
import { cache } from "react";
import { priv } from "@app/lib/api";
import { AxiosResponse } from "axios";
import { GetIdpResponse } from "@server/routers/idp";
export const dynamic = "force-dynamic";
export default async function Page(props: {
params: Promise<{ orgId: string; idpId: string }>;
@@ -17,13 +20,14 @@ export default async function Page(props: {
const allCookies = await cookies();
const stateCookie = allCookies.get("p_oidc_state")?.value;
// query db directly in server component because just need the name
const [idpRes] = await db
.select({ name: idp.name })
.from(idp)
.where(eq(idp.idpId, parseInt(params.idpId!)));
if (!idpRes) {
const idpRes = await cache(
async () => await priv.get<AxiosResponse<GetIdpResponse>>(`/idp/${params.idpId}`)
)();
const foundIdp = idpRes.data?.data?.idp;
if (!foundIdp) {
return <div>IdP not found</div>;
}
@@ -35,7 +39,7 @@ export default async function Page(props: {
code={searchParams.code}
expectedState={searchParams.state}
stateCookie={stateCookie}
idp={{ name: idpRes.name }}
idp={{ name: foundIdp.name }}
/>
</>
);