From fefc314d35d4b35c615e126df3ba8d7f3c0e897b Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Thu, 7 Apr 2022 17:26:33 +0100 Subject: [PATCH] Fixing api points not returning (#2419) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Omar López --- packages/app-store/slackmessaging/api/add.ts | 7 +++---- packages/app-store/slackmessaging/api/callback.ts | 6 ++---- packages/app-store/slackmessaging/api/commandHandler.ts | 2 +- .../app-store/slackmessaging/api/interactiveHandler.ts | 4 ++-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/app-store/slackmessaging/api/add.ts b/packages/app-store/slackmessaging/api/add.ts index 5ccf21c4..e4aa5143 100644 --- a/packages/app-store/slackmessaging/api/add.ts +++ b/packages/app-store/slackmessaging/api/add.ts @@ -8,8 +8,7 @@ const scopes = ["commands", "users:read", "users:read.email"]; export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (!req.session?.user?.id) { - res.status(401).json({ message: "You must be logged in to do this" }); - return; + return res.status(401).json({ message: "You must be logged in to do this" }); } if (req.method === "GET") { @@ -31,7 +30,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const url = `https://slack.com/oauth/v2/authorize?${query}&user_`; // const url = // "https://slack.com/oauth/v2/authorize?client_id=3194129032064.3178385871204&scope=chat:write,commands&user_scope="; - res.status(200).json({ url }); + return res.status(200).json({ url }); } - res.status(404).json({ error: "Not Found" }); + return res.status(404).json({ error: "Not Found" }); } diff --git a/packages/app-store/slackmessaging/api/callback.ts b/packages/app-store/slackmessaging/api/callback.ts index 6fca42be..20541a0f 100644 --- a/packages/app-store/slackmessaging/api/callback.ts +++ b/packages/app-store/slackmessaging/api/callback.ts @@ -8,14 +8,12 @@ const client_secret = process.env.SLACK_CLIENT_SECRET; export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (!req.session?.user?.id) { - res.status(401).json({ message: "You must be logged in to do this" }); - return; + return res.status(401).json({ message: "You must be logged in to do this" }); } if (req.method === "GET") { // Get user const { code } = req.query; - console.log(req.query); if (!code) { res.redirect("/apps/installed"); // Redirect to where the user was if they cancel the signup or if the oauth fails @@ -46,6 +44,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }, }, }); - res.redirect("/apps/installed"); + return res.redirect("/apps/installed"); } } diff --git a/packages/app-store/slackmessaging/api/commandHandler.ts b/packages/app-store/slackmessaging/api/commandHandler.ts index 4af418da..57845cb3 100644 --- a/packages/app-store/slackmessaging/api/commandHandler.ts +++ b/packages/app-store/slackmessaging/api/commandHandler.ts @@ -24,5 +24,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) return res.status(404).json({ message: `Command not found` }); } } - res.status(400).json({ message: "Invalid request" }); + return res.status(400).json({ message: "Invalid request" }); } diff --git a/packages/app-store/slackmessaging/api/interactiveHandler.ts b/packages/app-store/slackmessaging/api/interactiveHandler.ts index 740e6660..290c4774 100644 --- a/packages/app-store/slackmessaging/api/interactiveHandler.ts +++ b/packages/app-store/slackmessaging/api/interactiveHandler.ts @@ -16,8 +16,8 @@ export default async function interactiveHandler(req: NextApiRequest, res: NextA case InteractionEvents.CREATE_EVENT: return await createEvent(req, res); default: - res.status(200).end(); // Techincally an invalid request but we don't want to return an throw an error to slack - 200 just does nothing + return res.status(200).end(); // Techincally an invalid request but we don't want to return an throw an error to slack - 200 just does nothing } } - res.status(200).end(); // Send 200 if we dont have a case for the action_id + return res.status(200).end(); // Send 200 if we dont have a case for the action_id }