calcom/pages/api/me.ts
Omar López 84d75cf693
Upgrades next-auth to v4 (#1185)
* Upgrades next-auth to v4

* Fixes next-auth session types

* Type fixes

* Fixes login issue

* Team page fixes

* Type fixes

* Fixes secret

* Adds test for forgotten password

* Skips if pw secret is undefined

* Prevents error if PW secret is undefined

* Adds PLAYWRIGHT_SECRET explainer

* Adds pending auth TODOs

* Adds missing secret

* Fixed imports

* Fixed imports

* Type fixes

* Test fixes

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-01-07 20:23:37 +00:00

45 lines
1,019 B
TypeScript

import type { NextApiRequest, NextApiResponse } from "next";
import { getSession } from "@lib/auth";
import prisma from "@lib/prisma";
import { defaultAvatarSrc } from "@lib/profile";
/**
* @deprecated Use TRCP's viewer.me query
*/
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const session = await getSession({ req });
if (!session) {
res.status(401).json({ message: "Not authenticated" });
return;
}
const user = await prisma.user.findUnique({
rejectOnNotFound: true,
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,
});
}