@TiTiTools wrote:
Dear friends, greetings to all!!
I’m Pedro, a new kind of programmer…
I’m trying to sync asyncronous callings to do a google authentication, but it’s not following the supposed order (and I’m getting crazy). It’s getting doing login, but not in the correct order…
Can anybody help me, pleeeeasee??
This is the main code:
this.authProvider.getGoogleLoginCredential() .then(() => { console.log("1: entering firebaseAuthentication"); this.authProvider.firebaseAuthentication(); console.log("3: exiting firebaseAuthentication"); }).then(() => { console.log("entering getUser().uid"); this.authProvider.getUser().uid; }).then(() => {
Here authProvider where methods are called:
public firebaseAuthentication(): Promise {
return this.afAuth.auth.signInWithCredential(this.credential)
.then((success) => {
console.log('2: Firebase Authentication success: ’ + JSON.stringify(success));
})
}getGoogleLoginCredential(): Promise {
return this.googlePlus.login({
webClientId:
‘xyxy.apps.googleusercontent.com’
, offline: false
}).then(res => {
this.googleLoginData = (res);
console.log(this.googleLoginData);
this.credential = firebase.auth.GoogleAuthProvider.credential(
res.idToken
);
console.log(this.credential);
}
).catch(err => console.error(err));
}And here is the result:
1: entering firebaseAuthentication
modal-login.ts:63
3: exiting firebaseAuthentication
modal-login.ts:65
entering getUser().uidTypeError: Cannot read property ‘uid’ of null
at modal-login.ts:66
at t.invoke (polyfills.js:3)
at Object.onInvoke (core.es5.js:3890)
…modal-login.ts:68
2: Firebase Authentication success: {“uid”:"RIvKWOi … }
Posts: 1
Participants: 1