While deploying my Next.js app to production via Vercel, I encountered an error related to a Prisma query in one of the API endpoints. The error message states:
Type error: Type '{ activated: true; }' is not assignable to type 'UserWhereInput'.
Object literal may only specify known properties, and 'activated' does not exist in type 'UserWhereInput'.
I am certain that activated
is defined in my schema. How can I resolve this Typescript issue? Below is the code snippet in question:
// ../api/alert.ts
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "../../lib/prisma";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method === "POST") {
try {
const { authorization } = req.headers;
if (authorization === `Bearer ${process.env.API_SECRET_KEY}`) {
//make sure the service that is calling this API endpoint is authorized
//get all users that are activated
const activeUsers = prisma.user.findMany({
where: { activated: true },
});
// do other stuff
res.status(200).json({ success: true });
} else {
res.status(401).json({ success: false });
}
} catch (err) {
res.status(500).json({ statusCode: 500 });
}
} else {
res.setHeader("Allow", "POST");
res.status(405).end("Method Not Allowed");
}
}
schema.prisma
...
model User {
id String @id @default(cuid())
phone String
createdAt DateTime @default(now())
activated Boolean @default(false)
Message Message[]
}
/lib/prisma.ts
import { PrismaClient } from "@prisma/client";
let prisma: PrismaClient;
if (process.env.NODE_ENV === "production") {
prisma = new PrismaClient();
} else {
let globalWithPrisma = global as typeof globalThis & {
prisma: PrismaClient;
};
if (!globalWithPrisma.prisma) {
globalWithPrisma.prisma = new PrismaClient();
}
prisma = globalWithPrisma.prisma;
}
export default prisma;