Skip to content

Conversation

@codebyemily
Copy link
Contributor

issue #2016

Copy link
Contributor

@adarshm11 adarshm11 left a 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

Comment on lines 18 to 21
if (apiResponse.remainingAttempts != undefined){
bannerCallback(`Wrong Code - You have ${apiResponse.remainingAttempts} left. Status Code: ${apiResponse.responseData || 500}`, 'red');
return;
}
Copy link
Contributor

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

Comment on lines 16 to 20
const data = await res.json();
status.responseData = res.status;
status.error = !res.ok;
status.remainingAttempts = data.remainingAttempts;
status.message = data.error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.',
Copy link
Contributor

@adarshm11 adarshm11 Feb 2, 2026

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){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (apiResponse.remainingAttempts != undefined){
if (apiResponse.remainingAttempts) {

});
status.responseData = res.status;
status.error = !res.ok;
if (res.status == TOO_MANY_ATTEMPTS) {
Copy link
Contributor

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({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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({

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants