I'm trying to get this sign in screen to work and I'm using express-async-handler and I'm putting in the email and password using ARC and I get a 404 not found error and from the debugging I can do I doesn't seem to be getting into the function. I'm not sure what to do at this point. Please help thanks. Screenshot
import express from "express";
import User from "../models/userModel.js";
import bcrypt from "bcryptjs";
import { generateToken } from "../utils.js";
import expressAsyncHandler from "express-async-handler";
const userRouter = express.Router();
userRouter.post(
"/signin",
expressAsyncHandler(async (req, res) => {
const user = await User.findOne({ email: req.body.email });
if (user) {
console.log("found");
if (bcrypt.compareSync(req.body.password, user.password)) {
res.send({
_id: user._id,
name: user.name,
email: user.email,
token: generateToken(user),
});
return;
}
console.log(req.body.password);
console.log(user.password);
}
res.status(401).send({ message: "Invalid email or password" });
})
);
export default userRouter;
Via Active questions tagged javascript - Stack Overflow https://ift.tt/jRP1owJ
Comments
Post a Comment