【发布时间】:2016-07-15 21:44:20
【问题描述】:
我正在使用 AngularJS 2 开发一个简单的 MEAN 堆栈应用程序。我正在使用 passportJS 和 jwt strategy + angular2-jwt 辅助库。
这是我的 Angular 代码,它处理登录代码。我已经测试了 API 并且它可以工作(使用邮递员)。
//login.component.ts:
onSubmit(credentials):void {
console.log("on SUbmit here");
this._userService.login(credentials.email, credentials.password)
.subscribe((result) => {
if (result) {
console.log("Link to Todo?");
this._router.navigate(['TodoComponent']);
}
});
}
//user.service.ts:
signUp(firstName, lastName, email, password) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
let user = new URLSearchParams();
user.set('email', email);
user.set('password', password);
user.set('firstName', firstName);
user.set('lastName', lastName);
return this._http
.post('/signup', user.toString(), { headers })
.map(res => res.json())
.map((res) => {
console.log(res.success);
return res.success;
});
}
但是,当我提交登录按钮时,我收到此错误:
未捕获(承诺):错误:JWT 必须有 3 个部分
我应该怎么做才能确保以正确的格式提供 JWT 并避免这些错误?
【问题讨论】:
标签: angular passport.js jwt