2022-02-04 18:30:52 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { stringify } from "querystring";
|
|
|
|
|
2022-05-02 23:13:34 +00:00
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
2022-03-23 22:00:30 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
2022-02-04 18:30:52 +00:00
|
|
|
|
2022-05-02 23:13:34 +00:00
|
|
|
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
|
|
|
|
|
|
|
|
let client_id = "";
|
|
|
|
let base_url = "";
|
2022-02-04 18:30:52 +00:00
|
|
|
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
|
|
if (req.method === "GET") {
|
|
|
|
// Get user
|
2022-08-31 19:44:47 +00:00
|
|
|
await prisma.user.findFirstOrThrow({
|
2022-02-04 18:30:52 +00:00
|
|
|
where: {
|
2022-03-23 22:00:30 +00:00
|
|
|
id: req.session?.user?.id,
|
2022-02-04 18:30:52 +00:00
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-05-02 23:13:34 +00:00
|
|
|
const appKeys = await getAppKeysFromSlug("tandem");
|
|
|
|
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id;
|
|
|
|
if (typeof appKeys.base_url === "string") base_url = appKeys.base_url;
|
|
|
|
if (!client_id) return res.status(400).json({ message: "Tandem client_id missing." });
|
|
|
|
if (!base_url) return res.status(400).json({ message: "Tandem base_url missing." });
|
|
|
|
|
|
|
|
const redirect_uri = encodeURI(WEBAPP_URL + "/api/integrations/tandemvideo/callback");
|
2022-02-04 18:30:52 +00:00
|
|
|
|
|
|
|
const params = {
|
|
|
|
client_id,
|
|
|
|
redirect_uri,
|
|
|
|
};
|
|
|
|
const query = stringify(params);
|
2022-05-02 23:13:34 +00:00
|
|
|
const url = `${base_url}/oauth/approval?${query}`;
|
2022-02-04 18:30:52 +00:00
|
|
|
res.status(200).json({ url });
|
|
|
|
}
|
|
|
|
}
|