-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new API endpoints for authentication response and test requests
- Loading branch information
1 parent
aca8efe
commit 768e9d5
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }); | ||
} |