Skip to content

Instantly share code, notes, and snippets.

@rheajt
Created November 20, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rheajt/366a66f07b13e406ea59 to your computer and use it in GitHub Desktop.
Save rheajt/366a66f07b13e406ea59 to your computer and use it in GitHub Desktop.
Angular Problems!
app.factory('Auth', ['$firebaseAuth', 'FBURL',
function($firebaseAuth, FBURL) {
var ref = new Firebase(FBURL);
return $firebaseAuth(ref);
}]);
app.factory('User', ['FBURL', '$firebaseObject',
function(FBURL, $firebaseObject) {
var ref = new Firebase(FBURL + '/users');
var userData = {};
return {
setUser: function(authData) {
ref.child(authData.uid).once('value', function(snapshot) {
if(snapshot.exists()) {
userData = snapshot.val();
console.log(userData);
} else {
userData = {
email: authData.google.email,
avatar: authData.google.profileImageURL,
account: 'student'
}
console.log('new user');
ref.child(authData.uid).set(userData);
}
});
return userData;
},
getUser: function() {
return userData;
}
}
}]);
app.controller('IndexCtrl', ['$scope', '$location', 'Auth', 'User',
function($scope, $location, Auth, User) {
$scope.auth = Auth;
$scope.auth.$onAuth(function(authData) {
if(authData) {
User.setUser(authData);
$location.path('/main');
}
});
}]);
app.controller('MainCtrl', ['$scope', 'Auth', '$location', 'User',
function($scope, Auth, $location, User) {
$scope.auth = Auth;
$scope.auth.$onAuth(function(authData) {
if(authData) {
$scope.authData = authData;
$scope.user = User;
} else {
$location.path('/');
}
})
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment