Res.render不与res.cookie合作

时间:2018-06-14 19:30:56

标签: javascript node.js

在我的代码中,我试图将令牌存储在cookie中,然后尝试呈现下一页。虽然它对登录发出了一个帖子请求,但它并没有真正呈现页面,甚至不会抛出任何错误。

var express = require('express');

var router = express.Router();

const User = require('../models/user');

var jwt = require('jsonwebtoken');

var path = require('path');

var app = express();

var apiRoutes = express.Router();

app.set('views', path.join(__dirname, 'views'));

app.use(express.static(path.join(__dirname, 'public')));

/* GET users listing. */

router.get('/', function (req, res, next) {

    console.log("are you doing it!")
    res.render('manager');

});



router.post('/signup', function (req, res) {

    console.log(req.body);
    User.signup(req, res); 

});


router.post('/signin', async function (req, res) {

    console.log("Reached!")

    // find the user

    // check existance of a user

    const user = await User.findUser(req.body.email); 

    // check password

    if (user) {
        const email= req.body.email;
        const password= req.body.password_digest;

        let test = await User.checkPassword(req.body.password, user.password_digest);

        console.log("Heytheree", test)

        if (test) {
            const user= {email, password} ;
            var token = req.cookies.token; 


            jwt.sign({
                user    
              }, `superSecret`, function(err, token){
                  console.log("are you", token);
                res.cookie("token", token)

              });

             res.render('/resumereview');

              console.log("Are we here", token);





        }

        else {

            res.json({ "Success": false });

            console.log("test2");



        }

    }




})



module.exports = router;

0 个答案:

没有答案