2017-04-25 179 views
0
app.post('/auth', function(req,res){ 
    console.log("post got", req.body) 
    if (req.body.username && req.body.password) { 
    db.get("select * from user where username='"+req.body.username+"' and password='"+req.body.password+"';", function(err, row){ 
     console.log(row) 
      if (row && row.username == req.body.username && row.password == req.body.password) { 
      var data = req.body; 
        var token = jwt.sign(data, 'shhhhh11'); 
        res.end(JSON.stringify({ 
        token: token 
        })); 
     } else { 
      res.end('authentication unsuccsessful'); 
     } 
    }); 
    } 
}); 

因此,本帖子令牌auth我如何从auth获取令牌以将其发布到localstorage客户端? 我如何定义的令牌,它CUS只设置能把我将令牌保存到本地存储

Uncaught ReferenceError: token is not defined 

回答

0

您可以设置令牌localStorage的有:

window.localStorage.setItem('token', token); 

您可以从localStorage的与得到的令牌

window.localStorage.getItem('token'); 
+0

它没有帮助,我需要帮助获取发布的数据,然后将其设置为本地存储。未捕获的ReferenceError:令牌未定义 – Infinito1337