Created
June 3, 2016 13:52
-
-
Save Kashkovsky/5b8016dc890f36a2106b1c11d8660964 to your computer and use it in GitHub Desktop.
AngularJS Authentication service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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