I have a login API that I use in my service
function logInToService(callback, errback, login, password, rememberLogin) { var url = "User/Login"; var authorizationHeader = {'Authorization': "Basic " + login + ":" + password}; httpWrapperService.post(url, {login: login, password: password}, authorizationHeader).then( function success(loginToken) {
And in my html header I show the username at the top when it logs in header.html
<div class="header-user-menu"> <div ng-show="isUserLoggedIn() == false "> <a href="" ng-click="$state.go('app.sr.login')" class="">{{'HEADER.LOGIN' | translate}}</a> </div> <div ng-show="isUserLoggedIn()" class="userName">{{'HEADER.WELCOME' | translate}} {{currentUser.emailAddress}}</div> </div>
and js file here
(function() { 'use strict'; angular .module('safe-repository') .controller('AppLayoutCtrl', appLayoutCtrl); // Implementation of controller appLayoutCtrl.$inject = ['$rootScope', '$scope']; function appLayoutCtrl($rootScope, $scope) { $scope.isUserLoggedIn = isUserLoggedIn; function isUserLoggedIn() { if ($rootScope.currentUser && $rootScope.currentUser.emailAddress != null && $rootScope.currentUser.emailAddress != '') { return true; } return false; } } })();
and here I have one logging service where I defined the logInToService method
function registrationService($rootScope, httpWrapperService, $modal, $state, $cookieStore) { var self = this; // expose functions self.hasUserAccessToLevel = hasUserAccessToLevel; self.logInToService = logInToService; self.getCurrentUserToken = getCurrentUserToken; self.showRegistrationViewForLevel = showRegistrationViewForLevel; self.currentUser = { //emailAddress: '', //password: '', //token: '' } $rootScope.currentUser = null; self.currentUserToken = null; function logInToservice (------){----}})();
The problem is that every time the user clicks the refresh button of the F5 page, the user logs out. Although I am trying to save data in localstorage, but in fact I am not getting a control flow.