2021-08-22 13:16:42 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
|
2021-08-22 13:16:42 +00:00
|
|
|
import { getSession } from "@lib/auth";
|
|
|
|
import { defaultAvatarSrc } from "@lib/profile";
|
|
|
|
|
2022-01-07 20:23:37 +00:00
|
|
|
/**
|
|
|
|
* @deprecated Use TRCP's viewer.me query
|
|
|
|
*/
|
2021-08-22 13:16:42 +00:00
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
2022-01-07 20:23:37 +00:00
|
|
|
const session = await getSession({ req });
|
2021-08-22 13:16:42 +00:00
|
|
|
if (!session) {
|
|
|
|
res.status(401).json({ message: "Not authenticated" });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-31 19:44:47 +00:00
|
|
|
const user = await prisma.user.findUniqueOrThrow({
|
2021-08-22 13:16:42 +00:00
|
|
|
where: {
|
|
|
|
id: session.user.id,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
username: true,
|
|
|
|
name: true,
|
|
|
|
email: true,
|
|
|
|
bio: true,
|
|
|
|
timeZone: true,
|
|
|
|
weekStart: true,
|
|
|
|
startTime: true,
|
|
|
|
endTime: true,
|
|
|
|
bufferTime: true,
|
|
|
|
theme: true,
|
|
|
|
createdDate: true,
|
|
|
|
hideBranding: true,
|
|
|
|
avatar: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
user.avatar = user.avatar || defaultAvatarSrc({ email: user.email });
|
|
|
|
|
|
|
|
res.status(200).json({
|
|
|
|
user,
|
|
|
|
});
|
|
|
|
}
|