cal.pub0.org/pages/api/me/_get.ts

23 lines
686 B
TypeScript
Raw Normal View History

import type { NextApiRequest } from "next";
import { defaultResponder } from "@calcom/lib/server";
import { schemaUserReadPublic } from "@lib/validations/user";
import { User } from ".prisma/client";
2022-09-06 17:40:23 +00:00
async function handler({
userId,
prisma,
}: NextApiRequest): Promise<{ error?: string; user?: Partial<User> }> {
const data = await prisma.user.findUniqueOrThrow({ where: { id: userId } });
if (!prisma) return { error: "Cant connect to database" };
2022-09-06 17:40:23 +00:00
if (!userId) return { error: "No user id found" };
if (!data) return { error: "You need to pass apiKey" };
const user = schemaUserReadPublic.parse(data);
return { user };
}
export default defaultResponder(handler);