2017-04-25 11 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に投稿します。トークンをローカルのクライアント側に投稿するにはどうすればよいでしょうか? どのように私はちょうどそれは、あなたがしてのlocalStorageにトークンを設定することができ、私にトークンをローカルストアに保存する

Uncaught ReferenceError: token is not defined 

答えて

0

を取得する設定CUSそれのためにトークンを定義することができます。

:あなたはとのlocalStorageからトークンを取得することができます

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

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

それは助けにはならない、私はポストされたデータを取得し、それをlocalstorageに設定するのに助けが必要です。未知のReferenceError:トークンが定義されていません – Infinito1337

関連する問題