Skip to content

Instantly share code, notes, and snippets.

@Kashkovsky
Created June 3, 2016 13:52
Show Gist options
  • Save Kashkovsky/5b8016dc890f36a2106b1c11d8660964 to your computer and use it in GitHub Desktop.
Save Kashkovsky/5b8016dc890f36a2106b1c11d8660964 to your computer and use it in GitHub Desktop.
AngularJS Authentication service
(function() {
'use strict';
app.factory('authService', authService);
authService.$inject = ['localStorageService'];
var authentication = {
isAuth: false,
customerId: 0
};
function authService(localStorageService) {
function authenticate(userId, token) {
localStorageService.set('authorizationData', { token: token, userName: userId });
authentication.isAuth = true;
authentication.customerId = customerId;
}
function fillAuthData() {
var authData = localStorageService.get('authorizationData');
if (authData) {
authentication.isAuth = true;
authentication.customerId = authData.customerId;
};
}
var service = {
authenticate: authenticate,
fillAuthData: fillAuthData,
authentication: authentication
};
return service;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment