Skip to content

Commit

Permalink
fix: fix lookup api route
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalsayed10 committed Apr 17, 2024
1 parent 93b0998 commit c097f4e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/pages/api/lookup.ts
Expand Up @@ -4,26 +4,26 @@ import type { NextApiRequest, NextApiResponse } from "next";

// POST - /api/lookup - Lookup verification status for a user
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const body = req.body;
const userId = body.text.split("|")[0].slice(2);
if (!userId) return res.status(400).json({ message: "Invalid user" });
const data = req.body;
const email = data.text;
if (!email) return res.status(400).json({ message: "Invalid user" });

if (!admins.includes(body.user_id)) return res.status(401).json({ message: "Unauthorized" });
if (!admins.includes(data.user_id)) return res.status(401).json({ message: "Unauthorized" });

try {
const record = await base("Users")
.select({ filterByFormula: `{Hack Club Slack ID} = '${userId}'` })
.select({ filterByFormula: `{Email} = '${email}'` })
.firstPage();

if (record.length > 0) {
return res
.status(200)
.json(`Verification Status for <@${userId}>: ${record[0].fields["Verification Status"]}`);
.json(`Verification Status for ${email}: ${record[0].fields["Verification Status"]}`);
} else {
return res
.status(200)
.json(
`User <@${userId}> not verified. Ask them to head over to https://verify.hackclub.dev to get verified.`
`User ${email} not found or not verified. Ask them to head over to https://verify.hackclub.dev to get verified.`
);
}
} catch (error: any) {
Expand Down

0 comments on commit c097f4e

Please sign in to comment.