Skip to content
This repository has been archived by the owner on Apr 2, 2018. It is now read-only.

No error handler for Auth.login #22

Closed
paoesco opened this issue Oct 4, 2016 · 7 comments
Closed

No error handler for Auth.login #22

paoesco opened this issue Oct 4, 2016 · 7 comments

Comments

@paoesco
Copy link

paoesco commented Oct 4, 2016

Hello,

I am trying to show error when a login attempt is done.
However, I can't find in the documentation https://docs.ionic.io/services/auth/#login if there is any error handler for login method.

There is one existing for the signup method and is working well.

Does it exist ? if yes, is it possible to update the doc ?

Thanks.

Your system information:

Cordova CLI: 6.3.1
Ionic Framework Version: 2.0.0-rc.0
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
OS: Windows 7 SP1
Node Version: v6.6.0

@olivercodes
Copy link
Contributor

olivercodes commented Oct 5, 2016

Currently, you would just do the following, essentially a typical promise handler:

this.auth.login('basic', details).then( () => {
  //success
}, (err) => {
  // Do something with err such as
  console.log(err.message);
})

If you were to use it incorrectly, say you spell the parameter keyword email wrong, err.message will contain:
email and password are required for basic authentication

If login fails, it will say UNAUTHORIZED

Or if the email is not actually an email (say instead of blah@blah.com you just sent blah for the email) you will get back Unprocessable Entity

I do agree with you that the signup function's returned email object is quite a bit more useful, I will work on adding an improved error type for login.

For now, I'll update the docs to include this more complete example. Thanks for the feedback!


P.S.If you wanted to look more in depth at the implementation, you can see it here:
https://github.com/driftyco/ionic-cloud/blob/master/src/auth.ts/#L467

@olivercodes olivercodes self-assigned this Oct 5, 2016
@paoesco
Copy link
Author

paoesco commented Oct 6, 2016

Thanks for the completeness of the answer !

@cfjedimaster
Copy link

Query - is there any reason why error handling is done differently for registration versus login? I just assumed I could follow the same pattern and expect IDetailedError<string[]>, but obviously that is not the case.

@cfjedimaster
Copy link

As an example, sending "pp" as the email address gives you UNPROCESSABLE ENTITY. Compare that to the nice invalid_email you get from registration. Is there a reason why this is being handled a bit more rough?

@ericb
Copy link
Contributor

ericb commented Nov 22, 2016

@cfjedimaster Fair question, i'll see what we can do about that. 🤔

@MvRemmerden
Copy link

With ionic 2.0 finished and the current focus on the services, can we expect any improvements in this area the next couple of weeks? Without getting back detailed errors, building a user-friendly authentication system is impossible.

@pwagner
Copy link

pwagner commented Apr 11, 2017

It seems to me as if the error handler never gets called, when custom auth with a hidden inAppBrowser is used. This ionic-cloud issue is related, but also closed: ionic-team/legacy-ionic-cloud#53
I'm wondering where the right place for an open issue about this would be. Any ideas?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants