If I start the app, then login as USER_A all of the auth data is fine, but when I logout as USER_A then immediately log back in as USER_B, the auth data is is set back to USER_A, but if I reload the app, the auth data is set to USER_B, without me having to login again.
Here are my factories:
.factory('FirebaseAuth', function ($firebaseAuth) {
return $firebaseAuth(new Firebase('https://myappname.firebaseio.com'));
})
.factory('AuthData', function (FirebaseAuth) {
return FirebaseAuth.$getAuth();
})
And here are my controllers:
.controller('LoginCtrl', function ($scope, $state, AuthData, FirebaseAuth, $cordovaOauth) {
$scope.errors = [];
$scope.login = function () {
$scope.errors = [];
if (!!window.cordova) {
$cordovaOauth.facebook('myappid', ['user_friends']).then(function (result) {
FirebaseAuth.$authWithOAuthToken('facebook', result.access_token).then(function (authData) {
AuthData = authData;
$state.go('tab.dash');
}, function (error) {
$scope.errors.push(error.toString());
});
}, function (error) {
$scope.errors.push(error.toString());
});
} else {
FirebaseAuth.$authWithOAuthPopup('facebook').then(function (authData) {
AuthData = authData;
$state.go('tab.dash');
}, function (error) {
$scope.errors.push(error.toString());
});
}
};
});
.controller('SettingsCtrl', function ($scope, $state, AuthData, FirebaseAuth) {
$scope.logout = function () {
FirebaseAuth.$unauth();
AuthData = undefined;
$state.go('login');
};
})