Hello everyone. I’m trying to make Facebook Login in my app, the login and the logout is working, but once I login, I cannot manage to keep the user stay logged in. If I refresh the page or close the app and open again, it says I’m not logged in. I can’t find the problem, I will be happy if anyone can explain me what I’m doing wrong.
export class HomePage {
rootPage: any = HomePage;
public user:any = null;
logged ={
loggedIn: false,
}
constructor(public navCtrl: NavController, private afAuth: AngularFireAuth, private facebook: Facebook, private platform: Platform) {
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
this.logged.loggedIn = true;
this.user = firebase.auth().currentUser;
}
});
}
loginFacebook() {
if (this.platform.is('cordova')) {
return this.facebook.login(['email', 'public_profile'])
.then( response => {
const facebookCredential = firebase.auth.FacebookAuthProvider
.credential(response.authResponse.accessToken);
firebase.auth().signInWithCredential(facebookCredential)
.then( success => {
this.logged.loggedIn = true;
this.user = firebase.auth().currentUser;
});
}).catch((error) => { console.log(error) });
}
}
logout(){
this.afAuth.auth.signOut();
this.logged.loggedIn = false;
}
}