Skip to content

Commit

Permalink
chore: log error in access and usage
Browse files Browse the repository at this point in the history
  • Loading branch information
apsantiso committed Jun 18, 2024
1 parent 90d58da commit f4e98fa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
24 changes: 17 additions & 7 deletions src/app/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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(

Check warning on line 174 in src/app/routes/auth.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'hasReferralsProgram' is assigned a value but never used

Check warning on line 174 in src/app/routes/auth.ts

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

'hasReferralsProgram' is assigned a value but never used
userData,
userData.bridgeUser,
userData.userId,
);
} catch (err) {
console.error(`[ACCESS_ERROR_PAYMENTS] - Details:`, err);

Check warning on line 180 in src/app/routes/auth.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected console statement

Check failure on line 180 in src/app/routes/auth.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Strings must use singlequote

Check warning on line 180 in src/app/routes/auth.ts

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

Unexpected console statement

Check failure on line 180 in src/app/routes/auth.ts

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

Strings must use singlequote
}

console.log('Request before payments');

Check warning on line 183 in src/app/routes/auth.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected console statement

Check warning on line 183 in src/app/routes/auth.ts

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

Unexpected console statement
const user = {
email: req.body.email,
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/app/routes/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class BridgeController {
try{
usage = await this.service.User.getUsage((req as AuthorizedRequest).user);
}catch(err){
console.error(err);
console.error(

Check warning on line 20 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected console statement

Check warning on line 20 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

Unexpected console statement
`[REDIS_USAGE_ERROR] - Details:`, err

Check failure on line 21 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Strings must use singlequote

Check failure on line 21 in src/app/routes/bridge.ts

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

Strings must use singlequote
);
}

if(!usage){
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`, {
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit f4e98fa

Please sign in to comment.