Summary
Using ionic creator, I have an issue when login/logout my side menu informations keep previous user’s informations.
Using ionic creator, I have an issue when login/logout, my side menu informations (avatar, user name…) keep the previous user’s informations (I’m switching between two account to test). I don’t know how to refresh or delete all informations related to the previous user, to refresh my side menu for the next one. I can see in the console that the right values are loaded, but they don’t erase the previous one in the menu.
Any suggestions ?
Here is my code :
// SIGNOUT FUNCTION in the controller
$scope.signOut = function(){
firebase.auth().signOut().then(function() {
// This is to try to "clean" "clear" all informations of the previous user
$ionicLoading.show({
template: 'Logging out....'
});
$timeout(function () {
$ionicLoading.hide();
$ionicHistory.clearCache();
$ionicHistory.clearHistory();
$ionicHistory.nextViewOptions({
disableBack: true,
historyRoot: true
});
$state.go("connexion");
}, 30);
});
};
// MAJ DOM (menu) FUNCTION in the controller
// function used for refresh the menu informations (avatar, displayname...)
$scope.majDom = function()
{
//$state.reload();
var user = firebase.auth().currentUser;
var uid;
$scope.userData = user;
if (user !== null) {
$scope.userData.displayName = user.displayName;
$scope.userData.email = user.email;
$scope.userData.avatar = user.photoURL;
uid = user.uid;
//With these lines, I can read in the console that the right informations are loaded after a new login, but never appear in the menu, instead there are previous user's informations.
console.log("Avatar de l'user :", $scope.userData.avatar);
console.log("Nom de l'user :", $scope.userData.displayName);
console.log("Email de l'user :", $scope.userData.email);
}
}
// LOGIN FUNCTION in the controller
$scope.loginEmail = function($email, $password){
var alertPopup;
function signInSuccess(response) {
console.log('signInSuccess : ', response);
// This is to call a menu refresh, but dosen't work
$scope.majDom();
$state.go("menu.VNements");
}
firebase.auth().signInWithEmailAndPassword($email, $password)
.then(signInSuccess)
};
// MENU FUNCTION in the Menu Page of the creator
function ($scope, $stateParams, $state, $firebaseArray, $ionicHistory) {
//$ionicUser, $ionicAuth,
var user = firebase.auth().currentUser;
var uid;
$scope.userData = user;
$ionicHistory.clearCache();
$ionicHistory.clearHistory();
$ionicHistory.nextViewOptions({
disableBack: true,
historyRoot: true
});
if (user !== null) {
$scope.userData.displayName = user.displayName;
$scope.userData.email = user.email;
$scope.userData.avatar = user.photoURL;
uid = user.uid;
console.log("Avatar de l'user :", $scope.userData.avatar);
console.log("Nom de l'user :", $scope.userData.displayName);
console.log("Email de l'user :", $scope.userData.email);
}
In the side menu's HTML the Avatar is called like this :
{{userData.avatar}}
And the display name :
{{userData.displayName}}