feat: adds me endpoint that returns session info

pull/9078/head
Agusti Fernandez Pardo 2022-09-05 21:01:55 +02:00
parent 181921f9c7
commit bc8623edb8
1 changed files with 21 additions and 0 deletions

21
pages/api/me.ts Normal file
View File

@ -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<Response>
): Promise<{ error?: string; user?: Partial<User> }> {
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) }),
});