Skip to content

Instantly share code, notes, and snippets.

@andruu
Created August 15, 2013 02:59
Show Gist options
  • Save andruu/6237828 to your computer and use it in GitHub Desktop.
Save andruu/6237828 to your computer and use it in GitHub Desktop.
app.factory('Auth', function (Firebase, $rootScope, $localStorage) {
var auth = new FirebaseSimpleLogin(Firebase.reference, function (error, user) {
if (error) {
$rootScope.$emit('firebase.error', error);
} else if (user) {
// We have user
$localStorage.current_user = user;
$localStorage.logged_in = true;
$rootScope.$emit('firebase.logged_in');
} else {
// No user
$localStorage.logged_in = false;
}
});
var login = function (email, password) {
auth.login('password', {
email: email,
password: password,
rememberMe: true
});
};
var logout = function () {
auth.logout();
$localStorage.current_user = {};
$localStorage.logged_in = false;
};
var register = function (email, password) {
auth.createUser(email, password, function (error, user) {
if (error) {
$rootScope.$emit('firebase.error', error);
} else {
// We have user
$localStorage.current_user = user;
$localStorage.logged_in = true;
$rootScope.$emit('firebase.logged_in');
}
});
};
return {
login: login,
logout: logout,
register: register
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment