-
Notifications
You must be signed in to change notification settings - Fork 35
made attemptCount map to track # of attempts #2020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
adarshm11
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
| if (apiResponse.remainingAttempts != undefined){ | ||
| bannerCallback(`Wrong Code - You have ${apiResponse.remainingAttempts} left. Status Code: ${apiResponse.responseData || 500}`, 'red'); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we reach this case we know what kind of error it is, we don't need to give them a status code
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (apiResponse.remainingAttempts != undefined){ | |
| if (apiResponse.remainingAttempts) { |
| }); | ||
| status.responseData = res.status; | ||
| status.error = !res.ok; | ||
| if (res.status == TOO_MANY_ATTEMPTS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is TOO_MANY_ATTEMPTS defined in this file, if not you can write at the top of the file with the imports:
const TOO_MANY_ATTEMPTS = 429;
for now
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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({ |
issue #2016