Skip to content

Instantly share code, notes, and snippets.

@alex-hladun
Created September 30, 2021 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-hladun/0f99dd7dc29d09e05f66acd16ddf9f3f to your computer and use it in GitHub Desktop.
Save alex-hladun/0f99dd7dc29d09e05f66acd16ddf9f3f to your computer and use it in GitHub Desktop.
Route for authentication on login
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