Skip to content
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

wrong password login issue #148

Open
Muhammed-Rashid-07 opened this issue Apr 15, 2023 · 3 comments
Open

wrong password login issue #148

Muhammed-Rashid-07 opened this issue Apr 15, 2023 · 3 comments

Comments

@Muhammed-Rashid-07
Copy link

Muhammed-Rashid-07 commented Apr 15, 2023

when a user login with wrong password the server is crashing.
Can you assign me to fix this issue.

@adarsh2901
Copy link

the same is happening with me as well!!
Did you get how to fix it?

@migdalius
Copy link

migdalius commented Apr 17, 2023

In api > routes > auth.js

Change login request:

`router.post("/login", async (req, res) => {
try {
const user = await User.findOne({ username: req.body.username });

const hashedPassword = CryptoJS.AES.decrypt(
  user.password,
  process.env.PASS_SEC
);
const OriginalPassword = hashedPassword.toString(CryptoJS.enc.Utf8);

if (!user || OriginalPassword !== req.body.password) {
  res.status(401).json("Błędny login lub hasło użytkownika");
} else {
  const accessToken = jwt.sign(
    {
      id: user._id,
      isAdmin: user.isAdmin,
    },
    process.env.JWT_SEC,
    { expiresIn: "3d" }
  );

  const { password, ...others } = user._doc;

  res.status(200).json({ ...others, accessToken });
}

} catch (err) {
res.status(500).json(err);
}
});
`

Problem is solve here: https://stackoverflow.com/questions/7042340/error-cant-set-headers-after-they-are-sent-to-the-client

@manoj515876
Copy link

Sanj your assign me this possible. I will fix it.

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

No branches or pull requests

4 participants