Fixed invalid credential handling.

This commit is contained in:
DebaucheryLibrarian 2024-03-17 05:51:18 +01:00
parent 8a6e57365c
commit 6f27e0a7dd
2 changed files with 6 additions and 10 deletions

View File

@ -47,11 +47,9 @@ export async function login(credentials, userIp) {
const { user, stashes } = await fetchUser(credentials.username.trim(), { const { user, stashes } = await fetchUser(credentials.username.trim(), {
email: true, email: true,
raw: true, raw: true,
}); }).catch(() => {
if (!user) {
throw new HttpError('Username or password incorrect', 401); throw new HttpError('Username or password incorrect', 401);
} });
await verifyPassword(credentials.password, user.password); await verifyPassword(credentials.password, user.password);
@ -59,8 +57,6 @@ export async function login(credentials, userIp) {
.update('last_login', 'NOW()') .update('last_login', 'NOW()')
.where('id', user.id); .where('id', user.id);
console.log('login user', user);
logger.verbose(`Login from '${user.username}' (${user.id}, ${userIp})`); logger.verbose(`Login from '${user.username}' (${user.id}, ${userIp})`);
try { try {

View File

@ -46,14 +46,14 @@ export async function fetchUser(userId, options = {}) {
.groupBy('users.id', 'users_roles.role') .groupBy('users.id', 'users_roles.role')
.first(); .first();
if (!user) {
throw new HttpError(`User '${userId}' not found`, 404);
}
const stashes = await knex('stashes') const stashes = await knex('stashes')
.where('user_id', user.id) .where('user_id', user.id)
.leftJoin('stashes_meta', 'stashes_meta.stash_id', 'stashes.id'); .leftJoin('stashes_meta', 'stashes_meta.stash_id', 'stashes.id');
if (!user) {
throw HttpError(`User '${userId}' not found`, 404);
}
if (options.raw) { if (options.raw) {
return { user, stashes }; return { user, stashes };
} }