problem sending values from one route to another

1

I am making a login system with mysql I am not being able to pass the route values to another I want to move from router login to router users follow the code

    connection.query('SELECT * FROM users WHERE username = ?', [username], function(err, rows, fields) {
     if (err) {
     appData.error = 1;
     appData['data'] = 'Error Occured!';
     res.status(400).json(appData);
     } else {
     if (rows.length > 0) {
     if (rows[0].password == password) {

    if (rows[0].nivel== 1) {

       res.redirect(307, '/Administration');
    //eu quero passar o username/nivel para /Administration
  res.send(username);
    }else if (rows[0].nivel== 2) {
       res.redirect(307, '/Users');

    }
    else if (rows[0].nivel== 3) {
       res.redirect(307, '/usersvip');

    }
    else if (rows[0].nivel== 4) {
       res.redirect(307, '/moderador');

    }
    else if (rows[0].nivel== 2) {
       res.redirect(307, '/activar');

    }
    else {
         res.redirect(307, '/banned');
    }

the page where I want to receive the values

var express = require('express');
var router = express.Router();
router.post('/', function(req, res, next) {
  res.render('Administration/index', { title: 'Home'});

});


module.exports = router;
    
asked by anonymous 05.08.2018 / 18:19

1 answer

0

I got this way

const authenticateUser = async (connection,  req, res) => {

  const user = await User.findUser(connection, req.body.username)
    if(!user){
        return res.render('login/login',{error: true})
    }
    if(!await bcrypt.compare(req.body.password, user.password)){
        return res.render('login/login', {error: true})
}
    else{
      if(user.user_type_id==1){
        req.session.user = user
        res.locals.user = user
      res.redirect('/Administration/index');
    }else if(user.user_type_id==2){
      req.session.user = user
      res.locals.user = user
      res.redirect('/Administration/index');
    }else if(user.user_type_id==3){
      req.session.user = user
      res.locals.user = user
      res.redirect('/Administration/index');
    }else if(user.user_type_id==4){
      req.session.user = user
      res.locals.user = user
      res.redirect('/Administration/index');
      }
      else if(user.user_type_id==5){
        req.session.user = user
        res.locals.user = user
        res.redirect('/Administration/index');
    } else {
        console.log("banned");
    }



  }
}
    
25.08.2018 / 15:39