2017-04-25 177 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