I'm building a website using Angular and Firebase. I'm using Angularfire2 and AngularFireAuth libraries and GoogleAuthProvider (Google) as my authentication provider.
Here is my service code:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
@Injectable()
export class AuthenticationService {
user: Observable<firebase.User>;
constructor(public afAuth: AngularFireAuth) {
this.user = afAuth.authState;
}
login() {
this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
}
logout() {
this.afAuth.auth.signOut();
}
}
When a user 'logs out' of my site, it works, but seems to 'cache' the Google authentication. So when they attempt to login a second time I run into a few problems:
What am I doing wrong? Is there a way I can stop angularfire2/auth from caching these credentials? Is there a way to log users out of Google when they log out of my site?
This is expected as they are 2 separate systems and each Auth state is stored separately. Firebase Auth signOut
signs you out of Firebase. To sign out from Google, you have to go to google and sign out. If this is critical for your app, you can always on Firebase Auth sign out, redirect to the google logout page:
auth.signOut().then(() => {
window.location.assign('https://accounts.google.com/Logout');
}, (error) => {
console.log(error);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With