Created
September 30, 2021 18:52
Route for authentication on login
This file contains hidden or 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
import { Request, Response } from "express"; | |
import { createUser } from "./DynamoPuts"; | |
import { verifyLogin } from "./DynamoQueries"; | |
const registerRoutes = (dynamoEnabled: boolean) => { | |
const express = require("express"); | |
const router = express.Router(); | |
router.post("/login", async (req: Request, res: Response) => { | |
if (dynamoEnabled) { | |
try { | |
const loginResult = await verifyLogin({ | |
username: req.body.username, | |
password: req.body.password | |
}); | |
if (loginResult) { | |
res.send(JSON.stringify(loginResult)); | |
} else { | |
return res.sendStatus(500); | |
} | |
} catch (err) { | |
return res.sendStatus(500); | |
} | |
} else { | |
res.send( | |
JSON.stringify({ | |
username: req.body.username, | |
email: "test@test.com" | |
}) | |
); | |
} | |
}); | |
return router; | |
}; | |
export default registerRoutes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment