1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

add try-catch to demo auth middleware (#1044)

- Since we validate email used in auth the route function needs to
  handle the possibility that userService.loginUserWithoutPassword can
  throw.
This commit is contained in:
Christopher Kolstad 2021-10-19 14:24:23 +02:00 committed by GitHub
parent 72445b6423
commit 28d0238732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,16 +9,25 @@ function demoAuthentication(
): void {
app.post(`${basePath}/api/admin/login`, async (req, res) => {
const { email } = req.body;
const user = await userService.loginUserWithoutPassword(email, true);
const session = req.session || {};
// @ts-ignore
session.user = user;
// @ts-ignore
req.session = session;
res.status(200)
try {
const user = await userService.loginUserWithoutPassword(
email,
true,
);
const session = req.session || {};
// @ts-ignore
.json(req.session.user)
.end();
session.user = user;
// @ts-ignore
req.session = session;
res.status(200)
// @ts-ignore
.json(req.session.user)
.end();
} catch (e) {
res.status(400)
.json({ error: `Could not sign in with ${email}` })
.end();
}
});
app.use(`${basePath}/api/admin/`, (req, res, next) => {