I know there are similar questions posted, but I haven't been able to find a solution for my problem.

I am trying to create a user profile page where the user can change their information through a form that uses a POST request. However, when the value is entered in the input field, it returns null. I don't have this problem when reading the input data for authenticating a user.

Also, the user is found but req.body returns an empty object.

Tools used:

* Node.js v10.16.3
* Express v4.17.1
* ejs v2.7.1
* Express session v1.16.2
* Passport v^0.4.0
* cookie-parser 1.4.4
* body-parser v1.19.0

The user that is found: 

```
{ _id: 5daf5ef80fb0d909e099d211,
  username: 'assa',
  email: 'easy@gmail.com',
  password:
   '$2b$05$A81bqD56TDmNoWhiHJVwR.2L7iqZBrRwYu1FEe/bp0TlkTMEUREvS',
  firstName: 'test',
  __v: 0 }

```

app.js:

```
let express = require("express"),
    app = express(),
    bodyParser = require("body-parser"),
    cookieParser = require('cookie-parser'),
    session = require("express-session"),
    mongoose = require("mongoose"),
    passport = require("passport"),
    flash = require('connect-flash'),
    validator = require('express-validator'),
    LocalStrategy = require("passport-local"),
    MongoStore = require('connect-mongo')(session);

let indexRoutes = require('./routes/index');
let userRoutes = require('./routes/user');
let User = require("./models/user");

// APP CONFIGURATION
mongoose.connect("mongodb://localhost:27017/test", { useNewUrlParser: true, useUnifiedTopology: true, }).then(() => {
    console.log("Connected to MongoDB");
}).catch((error) => {
    console.log("Something is wrong...");
});

require('./config/passport');

// View engine setup
app.set("view engine", "ejs");
app.use(express.static(__dirname + "/public"));

// Initial setup
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(validator());

// Session setup
app.use(cookieParser());
app.use(session({
    secret: 'somesecretforbytox',
    resave: false,
    saveUninitialized: false
}));
app.use(flash());

// Initialize passport
app.use(passport.initialize());
app.use(passport.session());

app.use(function (req, res, next) {
    res.locals.currentUser = req.user;
    res.locals.session = req.session;
    next();
});

// ======================
// Connect to route files
// ======================
app.use('/user', userRoutes);
app.use(indexRoutes);

app.listen(3033, function () {
    console.log("Listening at port 3033...");
});

```

user.js

```
let express = require('express'),
    router = express.Router(),
    passport = require('passport');

let User = require("../models/user");

// user profile
router.get("/profile", isLoggedIn, function (req, res) {
    res.render("user/profile", { currentUser: req.user });
});

router.post('/profile', (req, res) => {
    updateRecord(req, res);
    res.redirect('/user/profile');
});

function updateRecord(req, res) {
    User.findOne({ 'id': req.user.id }, function (err, user) {
        let firstName = req.body.firstName;
        user.firstName = firstName;

        user.save(function (err, doc) {
            if (err) {
                return done(err);
            }
            return done(null, doc);
        });
    });
}

router.get("/profile/edit", isLoggedIn, function (req, res) {
     res.render("user/edit", { currentUser: req.user });

});

// ...sign in and signup routes

module.exports = router;

// middleware
function isLoggedIn(req, res, next) {
    if (req.isAuthenticated()) {
        return next();
    }
    res.redirect('/user/login');
}

```

profile.ejs:

```
<form action="/user/profile" method="POST" class="form-validate form-horizontal">
    <fieldset>
        <legend>Edit addresss</legend>
        <!-- email -->
        <div class="control-group">
            <div class="control-label">
                <label id="jform_email1-lbl" for="jform_email" class="hasPopover required" title="" data-content="Въведете имейл адрес." data-original-title="Email Address">
                    Email<span class="star">&nbsp;*</span></label>
            </div>
            <div class="controls">
                <input type="email" name="email" class="validate-email required" id="jform_email" value="<%= (typeof currentUser.email != 'undefined' ? currentUser.email : '') %>" size="30" autocomplete="email" required aria-required="true">
            </div>
        </div>
        <!-- name -->
        <div class="control-group">
            <div class="control-label">
                <label id="jform_fname-lbl" for="jform_fname" class="hasPopover required" title="" data-content="Въведете име." data-original-title="Name">
                    Name<span class="star">&nbsp;*</span></label>
            </div>
            <div class="controls">
                <input type="text" name="firstName" id="jform_fname" value="<%= (typeof currentUser.firstName != 'undefined' ? currentUser.firstName : '') %>" class="required" size="30" required aria-required="true">
            </div>
        </div>
    </fieldset>

    <div class="form-actions">
        <!-- <input type="hidden" name="_csrf" value=" csrfToken "> -->
        <button type="submit" class="btn btn-primary validate">
            <span>Save</span>
        </button>
        <!-- <input type="hidden" name="_csrf" value=" csrfToken "> -->
        <a class="btn" href="/" title="Cancel">Cancel</a>
    </div>
</form>

```

user schema:

```
let mongoose = require('mongoose');
let Schema = mongoose.Schema;
let bcrypt = require('bcrypt');

let userSchema = new Schema({
  username: { type: String, required: true },
  email: { type: String, required: true },
  password: { type: String, required: true },
  firstName: { type: String },
  lastName: { type: String },
  address: { type: String },
  zip: { type: String },
  country: { type: String },
  phone: { type: String }
});

userSchema.methods.encryptPassword = function (password) {
  return bcrypt.hashSync(password, bcrypt.genSaltSync(5), null);
};

userSchema.methods.validPassword = function (password) {
  return bcrypt.compareSync(password, this.password);
}

module.exports = mongoose.model('user', userSchema);

```