#ReferenceError: Buffer is not defined (Prisma Adapter PG)

3 messages · Page 1 of 1 (latest)

tranquil mountain
#

I am using prisma 7 in my tanstack start application.

I have created _protected route and am calling getUser function in beforeLoad.

The getUser function takes the email from the session and get the user from the pg database.

export const Route = createFileRoute("/_protected")({
  component: RouteComponent,
  beforeLoad: async () => {
    const user = await getUserServerFn();
    if (!user) throw redirect({ to: "/login" });
    return { user };
  },
});
export const getUser = async (email: string) => {
  return await prisma.user.findUnique({ where: { email } });
};

export const getUserServerFn = createServerFn().handler(async () => {
  const session = await useAppSession();
  const { email } = session.data;
  if (!email) return null;
  return await getUser(email);
});
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "generated/prisma/client";

const connectionString = `${process.env.DATABASE_URL}`;
const adapter = new PrismaPg({ connectionString });

declare global {
  var __prisma: PrismaClient | undefined;
}

export const prisma = globalThis.__prisma || new PrismaClient({ adapter });

if (process.env.NODE_ENV != "production") {
  globalThis.__prisma = prisma;
}
chrome sail
#

you have server code leaking to the client, try using createServerOnlyFn for getUser