feat: dont use ensureSession, but userId from req
parent
bc8623edb8
commit
4d74a6c896
|
@ -1,6 +1,5 @@
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
import { ensureSession } from "@calcom/lib/auth";
|
|
||||||
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
|
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
|
||||||
|
|
||||||
import { User } from ".prisma/client";
|
import { User } from ".prisma/client";
|
||||||
|
@ -10,10 +9,10 @@ async function handler(
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
_res: NextApiResponse<Response>
|
_res: NextApiResponse<Response>
|
||||||
): Promise<{ error?: string; user?: Partial<User> }> {
|
): Promise<{ error?: string; user?: Partial<User> }> {
|
||||||
const session = await ensureSession({ req });
|
if (!prisma) return { error: "Cant connect to database" };
|
||||||
/* Only admins can opt-in to V2 for now */
|
const user = await prisma.user.findUniqueOrThrow({ where: { id: req.userId } });
|
||||||
if (!session) return { error: "You need to be logged in" };
|
if (!user) return { error: "You need to pass apiKey" };
|
||||||
return { user: { ...session.user, email: session.user.email || "" } };
|
return { user };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defaultHandler({
|
export default defaultHandler({
|
||||||
|
|
Loading…
Reference in New Issue