From f4190bc3630a200c62dd8a02bdaaf746598b6d28 Mon Sep 17 00:00:00 2001 From: Andres Pinto Date: Wed, 13 Nov 2024 08:10:14 -0400 Subject: [PATCH] chore/add-log-on-unexpected-login-error --- src/app/routes/auth.ts | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/app/routes/auth.ts b/src/app/routes/auth.ts index 7c14d58a..8196612a 100644 --- a/src/app/routes/auth.ts +++ b/src/app/routes/auth.ts @@ -81,25 +81,32 @@ export class AuthController { throw createHttpError(401, 'Wrong login credentials'); } - const encSalt = this.service.Crypt.encryptText(user.hKey.toString()); - const required2FA = user.secret_2FA && user.secret_2FA.length > 0; + try { + const encSalt = this.service.Crypt.encryptText(user.hKey.toString()); + const required2FA = user.secret_2FA && user.secret_2FA.length > 0; - const hasKeys = await this.service.KeyServer.keysExists(user); + const hasKeys = await this.service.KeyServer.keysExists(user); - // TODO: If user has referrals, then apply. Do not catch everything - if (internxtClient === 'drive-mobile') { - this.service.UsersReferrals.applyUserReferral(user.id, 'install-mobile-app').catch((err: Error) => { - this.logReferralError(user.id, err); - }); - } + // TODO: If user has referrals, then apply. Do not catch everything + if (internxtClient === 'drive-mobile') { + this.service.UsersReferrals.applyUserReferral(user.id, 'install-mobile-app').catch((err: Error) => { + this.logReferralError(user.id, err); + }); + } - if (internxtClient === 'drive-desktop') { - this.service.UsersReferrals.applyUserReferral(user.id, 'install-desktop-app').catch((err: Error) => { - this.logReferralError(user.id, err); - }); - } + if (internxtClient === 'drive-desktop') { + this.service.UsersReferrals.applyUserReferral(user.id, 'install-desktop-app').catch((err: Error) => { + this.logReferralError(user.id, err); + }); + } - res.status(200).send({ hasKeys, sKey: encSalt, tfa: required2FA }); + return res.status(200).send({ hasKeys, sKey: encSalt, tfa: required2FA }); + } catch (err) { + this.logger.error( + `[AUTH/Login] USER: ${user.email} ERROR: ${(err as Error).message}, STACK: ${(err as Error).stack}`, + ); + throw err; + } } private logReferralError(userId: unknown, err: Error) {