ionic framework - TypeScript: Return Result of a Promise -
i working on ionic app uses fireface login facebook. followed docs here: https://github.com/angular/angularfire2/blob/master/docs/auth-with-ionic2.md
almost @ end of docs can see piece of code fb login (using native fb app if available):
signinwithfacebook(): firebase.promise<firebaseauthstate> { if (this.platform.is('cordova')) { return facebook.login(['email', 'public_profile']).then(res => { const facebookcredential = firebase.auth.facebookauthprovider.credential(res.authresponse.accesstoken); return firebase.auth().signinwithcredential(facebookcredential); }); } else { ... } }
this kind of screws return type of method signinwithfacebook. method should return result of promise triggered facebook.login(...) - return facebooklogin-promise has different data type. i'm bit confused how can re-model lines return promise created firebase.auth().signinwithcredential(facebookcredential).
do have hints/ideas?
thanks lot in advance!
ok, here solution (or work-around - whatever want call it).
what changed:
- the method signinwithfacebook return void
- it takes anonymous function argument gets executed when inner promise resolves
here code:
signinwithfacebook(success: (firebaseauthstate) => void): void { if (this.platform.is('cordova')) { facebook.login(['email', 'public_profile']).then(res => { const facebookcredential = firebase.auth.facebookauthprovider.credential(res.authresponse.accesstoken); firebase.auth().signinwithcredential(facebookcredential).then( fbas => success(fbas)); } ); } else { this.auth$.login({ provider: authproviders.facebook, method: authmethods.popup }).then(res => success(res)); } }
and how call method:
this._auth.signinwithfacebook2(res => {...});
Comments
Post a Comment