chore(repo): initialize planarchy workspace
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { createTRPCContext } from "@planarchy/api";
|
||||
import { appRouter } from "@planarchy/api/router";
|
||||
import { prisma } from "@planarchy/db";
|
||||
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { auth } from "~/server/auth.js";
|
||||
|
||||
const handler = async (req: NextRequest) => {
|
||||
const session = await auth();
|
||||
|
||||
const dbUser = session?.user?.email
|
||||
? await prisma.user.findUnique({
|
||||
where: { email: session.user.email },
|
||||
select: { id: true, systemRole: true, permissionOverrides: true },
|
||||
})
|
||||
: null;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const options: any = {
|
||||
endpoint: "/api/trpc",
|
||||
req,
|
||||
router: appRouter,
|
||||
createContext: () => createTRPCContext({ session, dbUser }),
|
||||
};
|
||||
|
||||
if (process.env["NODE_ENV"] === "development") {
|
||||
options.onError = ({ path, error }: { path?: string; error: { message: string } }) => {
|
||||
console.error(`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`);
|
||||
};
|
||||
}
|
||||
|
||||
return fetchRequestHandler(options);
|
||||
};
|
||||
|
||||
export { handler as GET, handler as POST };
|
||||
Reference in New Issue
Block a user