Ionic2 如何使用Ionic自定义身份验证处理登录错误?
我正在尝试使用Ionic Cloud的Auth服务实现用户登录,并且不希望在应用浏览器中显示Cordova。如果出现身份验证错误(例如错误的密码),我希望错误处理程序会启动,但由于某种原因,情况似乎从来没有这样 “我的登录”组件中的方法包含以下内容:Ionic2 如何使用Ionic自定义身份验证处理登录错误?,ionic2,jwt,Ionic2,Jwt,我正在尝试使用Ionic Cloud的Auth服务实现用户登录,并且不希望在应用浏览器中显示Cordova。如果出现身份验证错误(例如错误的密码),我希望错误处理程序会启动,但由于某种原因,情况似乎从来没有这样 “我的登录”组件中的方法包含以下内容: let loginData = { email: this.email, password: this.password }; let loginOptions: AuthLoginOptions = { inAppBrowserOpt
let loginData = {
email: this.email,
password: this.password
};
let loginOptions: AuthLoginOptions = {
inAppBrowserOptions: {
hidden: true
}
};
this.auth.login('custom', loginData, loginOptions).then(() => {
console.log('login success');
}, (err) => {
console.log('login error', err); // <-- this never gets executed.
});
我在github上发现了两个似乎相关的问题:
公共函数get\u login()
{
试一试{
$redirect\u uri=CustomAuthentication::process(
$\u获取['token'],
$\u获取[“状态”],
$\u GET['redirect\u uri']
);
返回Redirect::to($Redirect\u uri);
}捕获(\异常$e){
$redirect\u uri=$\u GET['redirect\u uri'].&'.http\u build\u query([
'错误'=>$e->getMessage(),
“状态”=>401,
'code'=>$e->getCode(),
]);
返回Redirect::to($Redirect\u uri);
}
}
(很抱歉,如果代码中有错误,我不知道Lavarel;))
此代码基于
在Ruby on Rails世界中:
error_params={error:error,state:401}
url=“#{params[:redirect_uri]}{error_params.to_query}”
重定向到url
我在服务器上做了此更改后,ionic应用程序立即开始工作。anyErrors:any
在controller.ts文件中
this.auth.login('basic', details).then(() => {
this.isUserLoggedIn = true; // <------ Debug here (1)
this.currentUserData = this.user;
console.log(this.currentUserData);
return this.currentUserData;
}, (err: IDetailedError) => {
this.anyErrors= err; // map the error here
});
this.auth.login('basic',details)。然后(()=>{
this.isUserLoggedIn=true;//{
this.anyErrors=err;//将错误映射到此处
});
在html文件中
{{anyErrors}}
this.auth.login('basic', details).then(() => {
this.isUserLoggedIn = true; // <------ Debug here (1)
this.currentUserData = this.user;
console.log(this.currentUserData);
return this.currentUserData;
}, (err: IDetailedError) => {
this.anyErrors= err; // map the error here
});