Im trying to create simple login app with MERN stack and i have an issue while using bcrypt to hash my password. server.js const mongoose = require("mongoose"); const express = require("express"); const cors = require("cors"); const passport = require("passport"); const passportLocal = require("passport-local").Strategy; const cookieParser = require("cookie-parser"); const bcrypt = require("bcrypt"); const session = require("express-session"); […]
Categories
Issue while calling hash method
- Post author By Full Stack
- Post date February 27, 2021
- No Comments on Issue while calling hash method
- Tags "password": "string", () => { console.log("Mongoose Is Connected"); } ); // Middleware app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ ex, () => { console.log("Server Has Started"); }); User.js const user = new mongoose.Schema({ username: String, (err) => { if (err) throw err res.send("Succesfully Authenticated") console.log(req.user), (req, { useNewUrlParser: true, }, } I have this error message in console when im testing my register route using postman and i cant get any response. (node:5452) UnhandledPr, }) ); app.use( session({ secret: "secretcode", }) ); app.use(cookieParser("secretcode")); app.use(passport.initialize()); app.use(passport.session()); //routes app.post('/login', }); await newUser.save(); res.send("User Created"); } }); }); app.get('/user', }); module.exports = mongoose.model("User", // <-- location of the react app were connecting to credentials: true, 10); const newUser = new User({ username: req.body.username, async (err, doc) => { if (err) throw err; if (doc) res.send("User Already Exists"); if (!doc) { const hashedPassword = bcrypt.h, err, Im trying to create simple login app with MERN stack and i have an issue while using bcrypt to hash my password. server.js const mongoose =, info) =>{ if (err) throw err if(!user) res.send("No user with given login") else { req.logIn(user, next) }) app.post("/register", next) => { passport.authenticate("local", or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, password: hashedpassword, password=pass, res) => { res.send(req.user) }) //listen app.listen(4000, res) => { User.findOne({ username: req.body.username }, res); }); }, resave: true, saveUninitialized: true, user) My postman post request on http://localhost:4000/register { "username":"user123", User>();, useUnifiedTopology: true