Skip to content

Instantly share code, notes, and snippets.

@majornorth
Created May 20, 2015 21:07
Show Gist options
  • Save majornorth/41ca94ad2b5afda0ae63 to your computer and use it in GitHub Desktop.
Save majornorth/41ca94ad2b5afda0ae63 to your computer and use it in GitHub Desktop.
WIP Angular + Firebase user auth with Email / Password
blocList.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
var ref = new Firebase("https://bloc-list.firebaseio.com");
return $firebaseAuth(ref);
}
]);
blocList.controller('Auth.controller', ['$scope', 'Auth', function($scope, Auth) {
$scope.createUser = function() {
Auth.$createUser({
email: $scope.email,
password: $scope.password
}).then(function(userData) {
console.log("User " + userData.uid + " created successfully!" + " Email: " + $scope.email + " Password: " + $scope.password + JSON.stringify(userData));
}).catch(function(error) {
console.log("There was an error: " + error);
});
Auth.$authWithPassword({
email : $scope.email,
password : $scope.password
}).then(function(authData) {
console.log("Logged in as:", authData.uid);
}).catch(function(error) {
console.error("Authentication failed:", error);
});
var authData = Auth.$getAuth();
if (authData) {
console.log("Logged in as:", authData.uid);
} else {
console.log("Logged out");
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment