Skip to content

Commit

Permalink
Add new API endpoints for authentication response and test requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ilaydacansinkoc committed Apr 18, 2024
1 parent aca8efe commit 768e9d5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
32 changes: 32 additions & 0 deletions vclogin/pages/api/getAuthResponse.ts
Original file line number Diff line number Diff line change
@@ -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<any>,
) {
//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" });
}
}
16 changes: 16 additions & 0 deletions vclogin/pages/api/new.ts
Original file line number Diff line number Diff line change
@@ -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<any>,
) {
return res.status(200).json({ message: "Hello World" });
}

0 comments on commit 768e9d5

Please sign in to comment.