Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question (not an issue) #1

Closed
gigocabrera opened this issue Jul 2, 2016 · 1 comment
Closed

Question (not an issue) #1

gigocabrera opened this issue Jul 2, 2016 · 1 comment

Comments

@gigocabrera
Copy link

Thank you very much for sharing your project 👍

In firebaseService.ts you have login(credentials) returning an Observable object

login(credentials) {
      var that = this
      return new Observable(observer => {
        return firebase.auth().signInWithEmailAndPassword(credentials.email, credentials.password)
          .then(function (authData) {
              console.log("Authenticated successfully with payload-", authData);
              observer.next(authData)
          }).catch(function (_error) {
              console.log("Login Failed!", _error);
              observer.error(_error)
          })
      });
    }

In my project I had something similar but returning a Promise

login(credentials): Promise<any> {
    return new Promise((resolve: () => void, reject: (reason: Error) => void) => {
      firebase.auth().authWithPassword({"email": credentials.email, "password": credentials.password}, (error: Error) => {
        if (error) {
          console.error('ERROR @ signInWithEmailPassword :', error);
          reject(error);
        }
        else {
          //console.log("Authenticated successfully:", this.authData);
          resolve();
        }
      });
    });
  }

What is the best practice for an ionic app? And when would you use one instead of the other?

(sorry if my questions are stupid but this technology is still a bit foreign to me)

@gigocabrera
Copy link
Author

Never mind. Found the answer!

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

No branches or pull requests

1 participant