Wait for authentication response from server before executing any Angularjs app -


i have angularjs app (bootstrapped using ng-admin) contained within admin backend initial login handled via ldap. when angular app loads first time, needs make api call (using restangular) server fetch token plus derive separate api url use. once token returned, it's stored in localstorage , passed subsequent api calls. because i'm not logging in in separate view, can't usual checking (via request interceptor or otherwise) see if token present , redirect login page if not.

what i've tried checking in request interceptor see if token present in localstorage, , if not, make api call , set it. however, because it's async, additional calls continue made , fail. i've tried checking in run method.

request interceptor:

restangularprovider.addfullrequestinterceptor(function(element, operation, what, url, headers, params) {     if (!localstorage.accesstoken) {         // no access token, stop additional requests until access token exists?         return false;     } }) 

inside run:

app.run(['restangular', '$rootscope', '$location', function(restangular, $rootscope, $location) {   if (! localstorage.accesstoken) {     var helper = require('./helper').helper;      helper.geteconomyconfig(restangular, $window, $rootscope);     // wait until return geteconomyconfig before continuing?   } }]); 

any or ideas appreciated @ point. tia


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -