diff --git a/pages/api/me.ts b/pages/api/me.ts deleted file mode 100644 index e6b1130b63..0000000000 --- a/pages/api/me.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import { defaultHandler, defaultResponder } from "@calcom/lib/server"; - -import { User } from ".prisma/client"; - -async function handler( - req: NextApiRequest, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - _res: NextApiResponse -): Promise<{ error?: string; user?: Partial }> { - if (!prisma) return { error: "Cant connect to database" }; - const user = await prisma.user.findUniqueOrThrow({ where: { id: req.userId } }); - if (!user) return { error: "You need to pass apiKey" }; - return { user }; -} - -export default defaultHandler({ - GET: Promise.resolve({ default: defaultResponder(handler) }), -}); diff --git a/pages/api/me/_get.ts b/pages/api/me/_get.ts new file mode 100644 index 0000000000..7fe25139a8 --- /dev/null +++ b/pages/api/me/_get.ts @@ -0,0 +1,21 @@ +import type { NextApiRequest } from "next"; + +import { defaultHandler, defaultResponder } from "@calcom/lib/server"; + +import { schemaUserReadPublic } from "@lib/validations/user"; + +import { User } from ".prisma/client"; + +async function handler(req: NextApiRequest): Promise<{ error?: string; user?: Partial }> { + if (!prisma) return { error: "Cant connect to database" }; + console.log(req); + if (!req.userId) return { error: "No user id found" }; + const data = await prisma.user.findUniqueOrThrow({ where: { id: req.userId } }); + if (!data) return { error: "You need to pass apiKey" }; + const user = schemaUserReadPublic.parse(data); + return { user }; +} + +export default defaultHandler({ + GET: Promise.resolve({ default: defaultResponder(handler) }), +}); diff --git a/pages/api/me/index.ts b/pages/api/me/index.ts new file mode 100644 index 0000000000..fe6357f6bc --- /dev/null +++ b/pages/api/me/index.ts @@ -0,0 +1,9 @@ +import { defaultHandler } from "@calcom/lib/server"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; + +export default withMiddleware("HTTP_GET")( + defaultHandler({ + GET: import("./_get"), + }) +);