Skip to content

Commit

Permalink
Make /admin/login return a descriptive error when no password is prov…
Browse files Browse the repository at this point in the history
…ided (#342)
  • Loading branch information
matt-fidd authored Apr 19, 2024
1 parent 44c7b4e commit 1bbba66
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/account-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ export function bootstrap(password) {
}

export function login(password) {
if (password === undefined || password === '') {
return { error: 'invalid-password' };
}

let accountDb = getAccountDb();
let row = accountDb.first('SELECT * FROM auth');

let confirmed = row && bcrypt.compareSync(password, row.password);

if (confirmed) {
Expand All @@ -59,7 +64,7 @@ export function login(password) {
// "session" that times out after a long time or something, and
// maybe each device has a different token
let row = accountDb.first('SELECT * FROM sessions');
return row.token;
return { token: row.token };
} else {
return null;
}
Expand Down
8 changes: 7 additions & 1 deletion src/app-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ app.post('/bootstrap', (req, res) => {
});

app.post('/login', (req, res) => {
let token = login(req.body.password);
let { error, token } = login(req.body.password);

if (error) {
res.status(400).send({ status: 'error', reason: error });
return;
}

res.send({ status: 'ok', data: { token } });
});

Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/342.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [matt-fidd]
---

Make /admin/login return a descriptive error when no password is provided

0 comments on commit 1bbba66

Please sign in to comment.