[UILabel mj_label]
所以这会将令牌发布到auth如何从auth获取令牌以将其发布到localstorage客户端? 如何为它定义令牌cus只是设置它让我
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');
}
});
}
});
答案 0 :(得分:0)
您可以使用以下命令将令牌设置为localStorage:
window.localStorage.setItem('token', token);
您可以通过以下方式从localStorage获取令牌:
window.localStorage.getItem('token');