2023-04-22 16:24:50 +00:00
|
|
|
import axios from "axios";
|
|
|
|
import { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
|
|
|
|
export default async function handleSlackAuthorize(req: NextApiRequest, res: NextApiResponse) {
|
2023-09-14 10:35:31 +00:00
|
|
|
try {
|
|
|
|
const { code } = req.body;
|
2023-04-22 16:24:50 +00:00
|
|
|
|
2023-09-14 10:35:31 +00:00
|
|
|
if (!code || code === "") return res.status(400).json({ message: "Code is required" });
|
2023-04-22 16:24:50 +00:00
|
|
|
|
2023-09-14 10:35:31 +00:00
|
|
|
const response = await axios({
|
|
|
|
method: "post",
|
|
|
|
url: process.env.SLACK_OAUTH_URL || "",
|
|
|
|
params: {
|
|
|
|
client_id: process.env.SLACK_CLIENT_ID,
|
|
|
|
client_secret: process.env.SLACK_CLIENT_SECRET,
|
|
|
|
code,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
res.status(200).json(response?.data);
|
|
|
|
} catch (error) {
|
|
|
|
res.status(200).json({ message: "Internal Server Error" });
|
|
|
|
}
|
2023-04-22 16:24:50 +00:00
|
|
|
}
|