title: Rolebased Login in Node.js Application
body: <p>I am currently trying to develop a role based administration. If a user is created at the moment, a "1" is stored in the database at "Admin". If it is a normal user, a "2" will be entered here. I want this to be read from the database and the distinction to be made so that the corresponding start page is displayed.</p>
  
  <p>What I have: </p>
  
  <p>user.js:</p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  const bcrypt = require('bcryptjs');
  const passport = require('passport');
  // Load User model
  const User = require('../DB/models/User');
  const { forwardAuthenticated } = require('../DB/config/auth');
  
  //User Models
  //const User = require('../DB/models/user');
  
  // Login Page
  router.get('/login', (req, res) =&gt; res.render('login'));
  
  //New User MA
  router.get ('/neuerUser_MA', (req, res) =&gt; res.render ('neuerUser_MA'));
  
  // Register
  router.post('/neuerUSer_MA', (req, res) =&gt; {
      const { username, admin, password, password2 } = req.body;
      let errors = [];
  
      if (password != password2) {
          errors.push({ msg: 'Passwords do not match' });
      }
  
      if (password.length &lt; 6) {
          errors.push({ msg: 'Password must be at least 6 characters' });
      }
  
      if (errors.length &gt; 0) {
          res.render('neuerUser_MA', {
              errors,
              username,
              admin,
              password,
              password2
          });
      } else {
          User.findOne({email: email}).then(user =&gt; {
              if (user) {
                  errors.push({msg: 'Email or Username already exists'});
                  res.render('neuerUser_MA', {
                      errors,
                      username,
                      admin,
                      password,
                      password2
                  });
              } else {
                  const newUser = new User({
                      username,
                      admin,
                      password
                  });
  
                  bcrypt.genSalt(10, (err, salt) =&gt; {
                      bcrypt.hash(newUser.password, salt, (err, hash) =&gt; {
                          if (err) throw err;
                          newUser.password = hash;
                          newUser
                              .save()
                              .then(user =&gt; {
                                  req.flash(
                                      'success_msg',
                                      'You are now registered and can log in'
                                  );
                                  res.redirect('/users/login');
                              })
                              .catch(err =&gt; console.log(err));
                      });
                  });
              }
          });
      }
  });
  
  // HOW I TRIED THE LOGIN:
  router.post('/login', (req, res, next) =&gt; {
      if(User.admin=="1"){
      passport.authenticate('local', {
          successRedirect: '/buchungen/startseite_breuninger',
          failureRedirect: '/users/login',
          failureFlash: true
      })(req, res, next);
      }
      else {
          passport.authenticate('local', {
              successRedirect: '/buchungen/startseite_spediteur',
              failureRedirect: '/users/login',
              failureFlash: true
          })(req, res, next);
      }
  });
  
  module.exports = router;
  </code></pre>
  
  <p>But reading from the database does not work. Regardless of what value is stored under "Admin", the start page from else{} is always shown.</p>
  
  <p>Maybe my approach is too simple. I'm still a beginner ;)
  Thanks already now for help!</p>