diff --git a/src/auth.js b/src/auth.js index 329d2df..998db0c 100755 --- a/src/auth.js +++ b/src/auth.js @@ -47,11 +47,9 @@ export async function login(credentials, userIp) { const { user, stashes } = await fetchUser(credentials.username.trim(), { email: true, raw: true, - }); - - if (!user) { + }).catch(() => { throw new HttpError('Username or password incorrect', 401); - } + }); await verifyPassword(credentials.password, user.password); @@ -59,8 +57,6 @@ export async function login(credentials, userIp) { .update('last_login', 'NOW()') .where('id', user.id); - console.log('login user', user); - logger.verbose(`Login from '${user.username}' (${user.id}, ${userIp})`); try { diff --git a/src/users.js b/src/users.js index 2f6a334..345eac5 100755 --- a/src/users.js +++ b/src/users.js @@ -46,14 +46,14 @@ export async function fetchUser(userId, options = {}) { .groupBy('users.id', 'users_roles.role') .first(); + if (!user) { + throw new HttpError(`User '${userId}' not found`, 404); + } + const stashes = await knex('stashes') .where('user_id', user.id) .leftJoin('stashes_meta', 'stashes_meta.stash_id', 'stashes.id'); - if (!user) { - throw HttpError(`User '${userId}' not found`, 404); - } - if (options.raw) { return { user, stashes }; }