made attemptCount map to track # of attempts#2020
made attemptCount map to track # of attempts#2020codebyemily merged 6 commits intoSCE-Development:devfrom
Conversation
adarshm11
left a comment
There was a problem hiding this comment.
we should also make it so that after every failed code, it returns to the frontend how many attempts are left, and the frontend modal says "wrong code - X attempts remaining" or something like that
| const data = await res.json(); | ||
| status.responseData = res.status; | ||
| status.error = !res.ok; | ||
| status.remainingAttempts = data.remainingAttempts; | ||
| status.message = data.error; |
There was a problem hiding this comment.
| const data = await res.json(); | |
| status.responseData = res.status; | |
| status.error = !res.ok; | |
| status.remainingAttempts = data.remainingAttempts; | |
| status.message = data.error; | |
| if (res.status == TOO_MANY_ATTEMPTS) { | |
| const data = await res.json(); | |
| status.responseData = data; | |
| status.error = false; | |
| } else { | |
| status.error = !res.ok; | |
| } |
TOO_MANY_ATTEMPTS might not exist as an enum in the frontend container, if so we can just hardcode an enum within this function for now
| const attempts = attemptCount.get(userId) ?? 0; | ||
|
|
||
| if (attempts >= MAX_ATTEMPTS){ | ||
| logger.error('User has made too many verification attempts.'); |
There was a problem hiding this comment.
| logger.error('User has made too many verification attempts.'); | |
| logger.error(`User ${userId} has made too many verification attempts.`); |
| logger.error('Error verifying payment for user:', userId); | ||
| return res.status(NOT_FOUND).send('Error verifying payment.'); | ||
| return res.status(NOT_FOUND).json({ | ||
| error: 'Error verifying payment.', |
There was a problem hiding this comment.
including "error" in the json body isn't necessary since it doesn't give us any insight into what happened and it isn't used on the frontend either
| user.token, | ||
| confirmationCode, | ||
| ); | ||
| if (apiResponse.remainingAttempts != undefined){ |
There was a problem hiding this comment.
| if (apiResponse.remainingAttempts != undefined){ | |
| if (apiResponse.remainingAttempts) { |
There was a problem hiding this comment.
i think if remainingAttempts is sent and it turns out there are 0 attempts left it will return false, but I want to check if remainingAttempts was sent over
so if it had 0 attempts left, that would never be displayed
There was a problem hiding this comment.
okay in that case it's fine, let's use !== instead of != though
| const attempts = attemptCount.get(userId) ?? 0; | ||
|
|
||
| if (attempts >= MAX_ATTEMPTS){ | ||
| logger.error(`User ${userId} has made too many verification attempts.`); return res.status(TOO_MANY_REQUESTS).json({ |
There was a problem hiding this comment.
| logger.error(`User ${userId} has made too many verification attempts.`); return res.status(TOO_MANY_REQUESTS).json({ | |
| logger.error(`User ${userId} has made too many verification attempts.`); | |
| return res.status(TOO_MANY_REQUESTS).json({ |
adarshm11
left a comment
There was a problem hiding this comment.
address the one comment then get one more approver
| user.token, | ||
| confirmationCode, | ||
| ); | ||
| if (apiResponse.remainingAttempts != undefined){ |
There was a problem hiding this comment.
okay in that case it's fine, let's use !== instead of != though
issue #2016