fix minor issues with login

This commit is contained in:
walljm 2019-09-05 11:43:27 -07:00
parent 5cfc34a1f2
commit f767cb4b85
2 changed files with 13 additions and 6 deletions

View File

@ -1,4 +1,4 @@
{ {
"printWidth": 120, "printWidth": 120,
"singleQuote": false "singleQuote": true
} }

View File

@ -62,8 +62,8 @@ export class ProfileService {
console.log('Saving the remote profile...'); console.log('Saving the remote profile...');
self.remoteProfile.ref.set(self.localProfile); self.remoteProfile.ref.set(self.localProfile);
console.log(' Finished saving remote profile. ' + self.elapsed(st, new Date()) + 'ms'); console.log(' Finished saving remote profile. ' + self.elapsed(st, new Date()) + 'ms');
self.needsSync = false;
} }
self.needsSync = false;
} }
poll(self); poll(self);
@ -80,7 +80,9 @@ export class ProfileService {
this.onLocalStorageLoaded.emit(this.localProfile); this.onLocalStorageLoaded.emit(this.localProfile);
}); });
this.firebaseAuth.authState.subscribe(state => this.subscribeToRemoteProfile(this.db, state)); this.firebaseAuth.authState.subscribe(state => {
this.subscribeToRemoteProfile(this.db, state);
});
} }
addSearchRequestToHistory(qry: string) { addSearchRequestToHistory(qry: string) {
@ -141,6 +143,14 @@ export class ProfileService {
} }
subscribeToRemoteProfile(db: AngularFireDatabase, user: firebase.User) { subscribeToRemoteProfile(db: AngularFireDatabase, user: firebase.User) {
// if this is a logout.
if (user === null) {
console.log('user signed out from FireBase');
this.remoteProfile = null; // inform the profile service not to bother
this.remoteLoggedIn = false;
return;
}
console.log('subscribeToRemoteProfile'); console.log('subscribeToRemoteProfile');
if (!user || this.firebaseUser) return; if (!user || this.firebaseUser) return;
console.log('You got the firebase user.'); console.log('You got the firebase user.');
@ -208,8 +218,6 @@ export class ProfileService {
authenticate() { authenticate() {
console.log('Authenticating to remote...'); console.log('Authenticating to remote...');
let self = this;
let provider = new firebase.auth.GoogleAuthProvider(); let provider = new firebase.auth.GoogleAuthProvider();
if (this.isWeb) { if (this.isWeb) {
this.firebaseAuth.auth.signInWithPopup(provider); this.firebaseAuth.auth.signInWithPopup(provider);
@ -225,7 +233,6 @@ export class ProfileService {
console.log(error); console.log(error);
}); });
} }
this.firebaseAuth.authState.subscribe(state => this.subscribeToRemoteProfile(this.db, state));
this.remoteLoggedIn = true; this.remoteLoggedIn = true;
} }