Merge pull request #158 from calcom/feat/me-endpoint
feat: adds me endpoint that returns session infopull/9078/head
commit
ddc084044a
|
@ -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<User> }> {
|
||||||
|
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) }),
|
||||||
|
});
|
|
@ -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"),
|
||||||
|
})
|
||||||
|
);
|
Loading…
Reference in New Issue