From 768e9d5e55a8f780ad4d2163127e123b3d82543b Mon Sep 17 00:00:00 2001 From: Ilayda Cansin Koc Date: Thu, 18 Apr 2024 14:28:11 +0000 Subject: [PATCH] Add new API endpoints for authentication response and test requests --- vclogin/pages/api/getAuthResponse.ts | 32 ++++++++++++++++++++++++++++ vclogin/pages/api/new.ts | 16 ++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 vclogin/pages/api/getAuthResponse.ts create mode 100644 vclogin/pages/api/new.ts diff --git a/vclogin/pages/api/getAuthResponse.ts b/vclogin/pages/api/getAuthResponse.ts new file mode 100644 index 0000000..36d1040 --- /dev/null +++ b/vclogin/pages/api/getAuthResponse.ts @@ -0,0 +1,32 @@ +import { NextApiRequest, NextApiResponse } from "next"; +import { Redis } from "ioredis"; + +var redis: Redis; +try { + redis = new Redis(parseInt(process.env.REDIS_PORT!), process.env.REDIS_HOST!); +} catch (error) { + console.error("Failed to connect to Redis:", error); +} + +export default async function handler( + req: NextApiRequest, + res: NextApiResponse, +) { + //Get Policy from request body + const { uuid } = req.body; + console.log("GET AUTH RESPONSE API"); + + // Read auth_res from redis and check if it matches the uuid + const auth_res = await redis.get("auth_res"); + console.log("auth_res: ", auth_res, uuid); + try { + if (auth_res === uuid) { + console.log("auth_res matches uuid"); + return res.status(200).json({ res: "success" }); + } else { + return res.status(200).json({ res: "no_match" }); + } + } catch { + return res.status(200).json({ res: "error" }); + } +} diff --git a/vclogin/pages/api/new.ts b/vclogin/pages/api/new.ts new file mode 100644 index 0000000..65d5d3c --- /dev/null +++ b/vclogin/pages/api/new.ts @@ -0,0 +1,16 @@ +import { NextApiRequest, NextApiResponse } from "next"; +import { Redis } from "ioredis"; + +var redis: Redis; +try { + redis = new Redis(parseInt(process.env.REDIS_PORT!), process.env.REDIS_HOST!); +} catch (error) { + console.error("Failed to connect to Redis:", error); +} + +export default async function handler( + req: NextApiRequest, + res: NextApiResponse, +) { + return res.status(200).json({ message: "Hello World" }); +}