Skip to content

Commit

Permalink
handle async functions properly
Browse files Browse the repository at this point in the history
  • Loading branch information
MegahNevel committed Dec 11, 2024
1 parent 2313bc4 commit f00f1fa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Controllers/membershipController.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const createMembershipForm = async (req, res) => {
numbers: true,
});

membership.password = hashSenha(temp_pass);
membership.password = await hashSenha(temp_pass);
await membership.save();
return res.status(201).send(membership);
} catch (error) {
Expand Down
12 changes: 7 additions & 5 deletions src/Controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const signUp = async (req, res) => {
numbers: true,
});

user.password = hashSenha(temp_pass);
user.password = await hashSenha(temp_pass);

await user.save();

Expand Down Expand Up @@ -84,7 +84,8 @@ const login = async (req, res) => {
return res
.status(400)
.send({ error: "Email ou senha inválidos." });
} else if (!comparaSenha(password, user.password)) {
// eslint-disable-next-line prettier/prettier
} else if (!(await comparaSenha(password, user.password))) {
return res
.status(400)
.send({ error: "Email ou senha inválidos." });
Expand Down Expand Up @@ -328,7 +329,7 @@ const changePassword = async (req, res) => {
return res.status(404).send({ message: "usuário não encontrado" });
}

user.password = hashSenha(newPassword);
user.password = await hashSenha(newPassword);

await user.save();
await Token.findOneAndDelete({ email: user.email });
Expand All @@ -355,13 +356,14 @@ const changePasswordInProfile = async (req, res) => {
if (!user) {
return res.status(404).send();
}
if (!comparaSenha(old_password, user.password)) {
// eslint-disable-next-line prettier/prettier
if (!(await comparaSenha(old_password, user.password))) {
return res.status(401).json({
mensagem: "Senha atual incorreta.",
});
}

user.password = hashSenha(new_password);
user.password = await hashSenha(new_password);
await user.save();

return res.status(200).json({
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/initDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const initializeRoles = async () => {
email: emailAdmin,
});
if (!existingAdmin) {
const hashedPassword = hashSenha(senhaAdmin);
const hashedPassword = await hashSenha(senhaAdmin);

const adminUser = new User({
name: "Admin",
Expand All @@ -122,7 +122,7 @@ const initializeRoles = async () => {
email: emailUser,
});
if (!ExistingSindicalizado) {
const hashedPassword = hashSenha(senhaUser);
const hashedPassword = await hashSenha(senhaUser);

const sindUser = new User({
name: "User",
Expand Down

0 comments on commit f00f1fa

Please sign in to comment.