2021-08-18 11:52:25 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { getSession } from "@lib/auth";
|
|
|
|
import prisma from "../../../../lib/prisma";
|
2021-06-10 23:37:58 +00:00
|
|
|
|
|
|
|
const client_id = process.env.ZOOM_CLIENT_ID;
|
|
|
|
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
2021-08-19 12:27:01 +00:00
|
|
|
if (req.method === "GET") {
|
|
|
|
// Check that user is authenticated
|
|
|
|
const session = await getSession({ req: req });
|
2021-06-10 23:37:58 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
if (!session) {
|
|
|
|
res.status(401).json({ message: "You must be logged in to do this" });
|
|
|
|
return;
|
|
|
|
}
|
2021-06-10 23:37:58 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
// Get user
|
|
|
|
await prisma.user.findFirst({
|
|
|
|
where: {
|
|
|
|
email: session.user.email,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
},
|
|
|
|
});
|
2021-06-10 23:37:58 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
const redirectUri = encodeURI(process.env.BASE_URL + "/api/integrations/zoomvideo/callback");
|
|
|
|
const authUrl =
|
|
|
|
"https://zoom.us/oauth/authorize?response_type=code&client_id=" +
|
|
|
|
client_id +
|
|
|
|
"&redirect_uri=" +
|
|
|
|
redirectUri;
|
2021-06-10 23:37:58 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
res.status(200).json({ url: authUrl });
|
|
|
|
}
|
2021-06-10 23:37:58 +00:00
|
|
|
}
|