H
H
Hiroshima2020-09-12 05:46:21
Node.js
Hiroshima, 2020-09-12 05:46:21

What does req.body.username do?

What does req.body.username do in this code?

var Schedule = require("../models/schedule"); 
router.post("/", async function(req, res, next) { 
    let user;
    if (req.body.username != null) {
        user = await Schedule.findOne({
            owner: {
                name: req.body.username,
                password: req.body.password
            }
        }); 
        if (user === null) {
            res.redirect('/register');
        }
        res.redirect(`/user/${req.body.username}`);
    }
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
drawnofmymind, 2020-09-12
@Hiroshima

Checks if there is a username value in the post request)
If it is in the top if = finds the username and password in the database
Yes = goes to the profile page,
No = goes to the registration page.
Regular login form in express

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question