Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Verify that name is alphanum+space & remove condition in catch
Browse files Browse the repository at this point in the history
  • Loading branch information
bguillaumat committed Jan 22, 2021
1 parent 9836253 commit a3b4efc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
16 changes: 1 addition & 15 deletions logic/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ async function changeName(name) {

changeNameStatus.percent = 40; // eslint-disable-line no-magic-numbers

let complete = false;
try {
// get user data
const user = await diskLogic.readUserFile();
Expand All @@ -65,25 +64,12 @@ async function changeName(name) {
// update user file
await diskLogic.writeUserFile({ ...user });

complete = true;

changeNameStatus.percent = 100;
} catch (error) {
if (error.response.status === constants.STATUS_CODES.UNAUTHORIZED) {
changeNameStatus.unauthorized = true;
} else {
changeNameStatus.error = true;
changeNameStatus.percent = 100;

throw error;
}
}

if (!complete) {
changeNameStatus.error = true;
changeNameStatus.percent = 100;

throw new Error('Unable to change name');
throw error;
}
}

Expand Down
1 change: 1 addition & 0 deletions routes/v1/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ router.post('/change-name', auth.jwt, safeHandler(async (req, res, next) => {

try {
validator.isString(newName);
validator.isAlphanumericAndSpaces(newName);
} catch (error) {
return next(error);
}
Expand Down

0 comments on commit a3b4efc

Please sign in to comment.