My Ionic 2 app integrates Google Authentication using Firebase. I have implemented a logout button within the app that calls the Firebase unauth()
method. However, this only disconnects the Firebase reference and does not terminate the Google OAuth session.
Upon pressing the logout button and then trying to log in again by clicking the login button, the user is automatically logged back in (using the previous OAuth session), which is not the desired behavior.
I am looking for a solution where my logout functionality also ends the Google OAuth session. This way, when the login button is clicked again, it should trigger a new prompt for the username and password. How can I accomplish this?
Below is an excerpt of the relevant code:
home.ts
import {Page} from 'ionic-angular';
@Page({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
firebaseUrl: string;
ref: Firebase;
constructor() {
this.firebaseUrl = 'https://xxx.firebaseio.com';
this.ref = new Firebase(this.firebaseUrl);
}
login() {
this.ref.authWithOAuthPopup("google", (error, authData) => {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});
}
logout() {
this.ref.unauth();
console.log('Logout button clicked');
}
}
home.html
<ion-navbar *navbar>
<ion-title>
Home
</ion-title>
</ion-navbar>
<ion-content class="home">
<button (click)="login()">Sign in with Google</button>
<button (click)="logout()">Logout</button>
</ion-content>