mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-09 01:17:06 +02: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:
parent
72445b6423
commit
28d0238732
@ -9,7 +9,11 @@ function demoAuthentication(
|
|||||||
): void {
|
): void {
|
||||||
app.post(`${basePath}/api/admin/login`, async (req, res) => {
|
app.post(`${basePath}/api/admin/login`, async (req, res) => {
|
||||||
const { email } = req.body;
|
const { email } = req.body;
|
||||||
const user = await userService.loginUserWithoutPassword(email, true);
|
try {
|
||||||
|
const user = await userService.loginUserWithoutPassword(
|
||||||
|
email,
|
||||||
|
true,
|
||||||
|
);
|
||||||
const session = req.session || {};
|
const session = req.session || {};
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
session.user = user;
|
session.user = user;
|
||||||
@ -19,6 +23,11 @@ function demoAuthentication(
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.json(req.session.user)
|
.json(req.session.user)
|
||||||
.end();
|
.end();
|
||||||
|
} catch (e) {
|
||||||
|
res.status(400)
|
||||||
|
.json({ error: `Could not sign in with ${email}` })
|
||||||
|
.end();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(`${basePath}/api/admin/`, (req, res, next) => {
|
app.use(`${basePath}/api/admin/`, (req, res, next) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user