From bc8623edb8e5633e13cdb457b04f794947afac80 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Mon, 5 Sep 2022 21:01:55 +0200 Subject: [PATCH] feat: adds me endpoint that returns session info --- pages/api/me.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 pages/api/me.ts diff --git a/pages/api/me.ts b/pages/api/me.ts new file mode 100644 index 0000000000..c66f6919ec --- /dev/null +++ b/pages/api/me.ts @@ -0,0 +1,21 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import { ensureSession } from "@calcom/lib/auth"; +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 }> { + const session = await ensureSession({ req }); + /* Only admins can opt-in to V2 for now */ + if (!session) return { error: "You need to be logged in" }; + return { user: { ...session.user, email: session.user.email || "" } }; +} + +export default defaultHandler({ + GET: Promise.resolve({ default: defaultResponder(handler) }), +});