From f4e98fad68b03afa671ea125f6d969113305547e Mon Sep 17 00:00:00 2001 From: Andres Pinto Date: Tue, 18 Jun 2024 13:51:06 -0400 Subject: [PATCH] chore: log error in access and usage --- src/app/routes/auth.ts | 24 +++++++++++++++++------- src/app/routes/bridge.ts | 4 +++- src/app/services/stripe.js | 2 +- src/app/services/user.js | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/app/routes/auth.ts b/src/app/routes/auth.ts index b2242783..9d77e791 100644 --- a/src/app/routes/auth.ts +++ b/src/app/routes/auth.ts @@ -27,13 +27,13 @@ export class AuthController { private config: Config; private logger: winston.Logger; - constructor(service: Services, config: Config) { + constructor (service: Services, config: Config) { this.service = service; this.config = config; this.logger = Logger.getInstance(); } - async register(req: Request<{ email: string }>, res: Response) { + async register (req: Request<{ email: string }>, res: Response) { // if (req.headers['internxt-client'] !== 'drive-mobile') { // const ipaddress = req.header('x-forwarded-for') || req.socket.remoteAddress; // await this.service.ReCaptcha.verify(req.body.captcha, ipaddress); @@ -61,7 +61,7 @@ export class AuthController { } } - async login(req: Request, res: Response) { + async login (req: Request, res: Response) { const internxtClient = req.headers['internxt-client']; if (!req.body.email) { @@ -102,7 +102,7 @@ export class AuthController { res.status(200).send({ hasKeys, sKey: encSalt, tfa: required2FA }); } - private logReferralError(userId: unknown, err: Error) { + private logReferralError (userId: unknown, err: Error) { if (!err.message) { return this.logger.error('[STORAGE]: ERROR message undefined applying referral for user %s', userId); } @@ -114,7 +114,7 @@ export class AuthController { return this.logger.error('[STORAGE]: ERROR applying referral for user %s: %s', userId, err.message); } - async access(req: Request, res: Response) { + async access (req: Request, res: Response) { const MAX_LOGIN_FAIL_ATTEMPTS = 10; const userData: any = await this.service.User.FindUserByEmail(req.body.email).catch(() => { @@ -170,6 +170,16 @@ export class AuthController { const keys = await this.service.KeyServer.getKeys(userData); const rootFolder = await this.service.Folder.getById(userData.root_folder_id); + try { + const hasReferralsProgram = await this.service.UsersReferrals.hasReferralsProgram( + userData, + userData.bridgeUser, + userData.userId, + ); + } catch (err) { + console.error(`[ACCESS_ERROR_PAYMENTS] - Details:`, err); + } + console.log('Request before payments'); const user = { email: req.body.email, @@ -208,14 +218,14 @@ export class AuthController { return res.status(200).json({ user, token, userTeam, newToken }); } - async getNewToken(req: Request, res: Response) { + async getNewToken (req: Request, res: Response) { const authRequest = req as Request & { user: UserAttributes }; const newToken = SignNewToken(authRequest.user, this.config.get('secrets').JWT, true); return res.status(200).json({ newToken }); } - async areCredentialsCorrect(req: Request, res: Response) { + async areCredentialsCorrect (req: Request, res: Response) { if (!req.query.hashedPassword) throw createHttpError(400, 'Query params must contain the hashedPassword property'); const { hashedPassword } = req.query; diff --git a/src/app/routes/bridge.ts b/src/app/routes/bridge.ts index e2fea80f..5118a61c 100644 --- a/src/app/routes/bridge.ts +++ b/src/app/routes/bridge.ts @@ -17,7 +17,9 @@ class BridgeController { try{ usage = await this.service.User.getUsage((req as AuthorizedRequest).user); }catch(err){ - console.error(err); + console.error( + `[REDIS_USAGE_ERROR] - Details:`, err + ); } if(!usage){ diff --git a/src/app/services/stripe.js b/src/app/services/stripe.js index c61e6568..50311ccc 100644 --- a/src/app/services/stripe.js +++ b/src/app/services/stripe.js @@ -48,8 +48,8 @@ module.exports = () => { const userExistsInPayments = async user => { const paymentsUrl = process.env.PAYMENTS_SERVER_URL; - console.log({ paymentsUrl }); const token = SignNewToken(user, process.env.JWT_SECRET, true); + console.log({ paymentsUrl, token, url: `${paymentsUrl}/users/exists` }); try { await axios.get(`${paymentsUrl}/users/exists`, { diff --git a/src/app/services/user.js b/src/app/services/user.js index 1bcf2f42..8158af01 100644 --- a/src/app/services/user.js +++ b/src/app/services/user.js @@ -553,7 +553,7 @@ module.exports = (Model, App) => { raw: true, }); - driveUsage = parseInt(usage[0].total); + const driveUsage = parseInt(usage[0]?.total ?? 0); const backupsQuery = await Model.backup.findAll({ where: { userId: targetUser.id },