Advanced Node and Express - Registration Route - Why use next(null user) instead of just next()?

Advanced Node and Express - Registration Route - Why use next(null user) instead of just next()?
0

#1

I can’t understand why the method next(null, user) is called at the end of the method below, if someone could help explain this to me, I would greatly appreciate it!

    app.route('/register')
      .post((req, res, next) => {

        db.collection('users').findOne({username: req.body.username}, function(err, user) {
            if(err) {
             next(err); 
            }
          
            else if(user){
             res.redirect('/'); 
            }
          
            else{
             db.collection('users').insertOne(
               {username: req.body.username,
                password: req.body.password},
               (err, doc) => {
                if(err) {
                   res.redirect('/'); 
                }
                else{ 
                 next(null, user); // Why would this be called, instead of just next()? Why the parameters?
                }
               }
             )     
            }      
        })},
            
      passport.authenticate('local', {failureRedirect: '/'}), 
            
      (req, res) => {
        res.redirect('/profile');
      }
   );

#2

Passing any arguments to next() triggers the error-handling middleware. If you don’t pass anything, it just goes to the next (non-error-handling) middleware. Not sure the reason for passing two arguments, given that I’ve only ever seen it used with a single argument (the error itself, generally)