-
Notifications
You must be signed in to change notification settings - Fork 8.4k
/
Copy path_getAdd.ts
33 lines (24 loc) · 1.04 KB
/
_getAdd.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { NextApiRequest, NextApiResponse } from "next";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { defaultResponder } from "@calcom/lib/server";
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
import { encodeOAuthState } from "../../_utils/oauth/encodeOAuthState";
async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!req.session?.user?.id) {
return res.status(401).json({ message: "You must be logged in to do this" });
}
const { client_id } = await getAppKeysFromSlug("closecom");
if (!client_id || typeof client_id !== "string")
return res.status(400).json({ message: "Close.com client_id missing." });
const state = encodeOAuthState(req) ?? "";
const params = new URLSearchParams({
client_id,
redirect_uri: `${WEBAPP_URL}/api/integrations/closecom/callback`,
response_type: "code",
state,
});
return res.status(200).json({
url: `https://app.close.com/oauth2/authorize/?${params.toString()}`,
});
}
export default defaultResponder(handler);