使用Angular应用程序中的passport jwt进行身份验证 我在Angular 4中设置了请求头,如下: 我在服务器端使用passport jwt,但是我得到了未经授权的错误。
`let strategy = new JwtStrategy(jwtOpts, (jwt_payload, cb)=>{
let stmt = "select * from user where id = ?";
let id = jwt_payload.id;
connection.query(stmt, id, (error, result) => {
if(error){
throw error;
}
if(result){
var userinfo = {
email: result[0].email,
id: result[0].id
}
cb(null, userinfo);
}
else{
cb(null, false);
}
})
})`
//this is my route
`app.use('/tournament',passport.authenticate('jwt', {session: false}), tour_route);`
//This is my angular call
createTournament(name: string){
this.token = 'JWT ' + this.authService.getToken();
const body = {
name
}
this.http.post('http://localhost:8000/tournament',
{
headers: new HttpHeaders().set('Authorization', this.token)
})
.subscribe(
response => {}
);
}
But i am getting an unauthorised access even if i am sending the right token