【发布时间】:2017-08-19 19:00:34
【问题描述】:
我正在尝试使用 ionic 框架(目前)登录到我在本地托管的应用程序。
这是我用于登录的 nodejs 后端代码,用于 Web 应用程序,但现在我也在为 android 平台制作它
// process the login form
app.post('/login', passport.authenticate('local-login', {
successRedirect: '/profile', // redirect to the secure profile section
failureRedirect: '/login', // redirect back to the signup page if there is an error
failureFlash: true // allow flash messages
}));
ionic 中的 HTML 代码
<ion-item>
<ion-input type="text" placeholder="Email" name="email" [(ngModel)]="email"></ion-input>
</ion-item>
<ion-item>
<ion-input type="password" placeholder="Password" name="password" [(ngModel)]="password"></ion-input>
</ion-item>
</ion-list>
调用的登录函数:
login() {
this.http.post('10.222.103.169:8080/login', JSON.stringify({ email: this.email, password: this.password }))
.map((response: Response) => {
let user = response.json();
console.log(user);
if (user && user.token) {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('currentUser', JSON.stringify(user));
}
}
}
如果我对帖子使用 .subscribe 方法,则会出现错误 其他登录方式:
login() {
this.http.post('10.222.103.169:8080/login', JSON.stringify({ email: this.email, password: this.password }))
.subscribe(data => {
console.log(data);
});
}
./LoginPage 类 LoginPage 中的运行时错误错误 - 导致:失败 在“XMLHttpRequest”上执行“打开”:无效的 URL
但链接正确且有效 现在的问题是它甚至没有向服务器发送 post 请求。
PS:我是 angular2 的新手。
【问题讨论】:
标签: node.js angular ionic2 passport.js passport-local