INNER CODE UNIT · JavaScript
authenticationRoute
danielstern/express-react-fullstack · src/server/authenticate.js:9
export const authenticationRoute = app => {
app.post('/authenticate',async (req,res)=>{
let { username, password } = req.body;
let db = await connectDB();
let collection = db.collection(`users`);
let user = await collection.findOne({name:username});
if (!user) {
return res.status(500).send(`User not found`);
}
let hash = md5(password);
let passwordCorrect = hash === user.passwordHash;
if (!passwordCorrect) {
return res.status(500).send('Password incorrect');
}
let token = uuid();