3

I'm using AngularJS with UI-Router and am attempting to attach a query parameter to a url on all http requests across my site.

I have an OAuth system on the backend and was previously applying Authorization headers to all requests, however to preserve backwards compatibility - have discovered I will have to instead apply a url parameter with the user identification to the backend.

My issue is that, I cannot use $httpInterceptor in the config portion of the app, because at that point in the app I don't have the current User, and can't inject $http to resolve the current user because that creates a circular dependency.

I was trying to use $http.defaults.transformRequest in the run portion of the app, but that didn't seem to be able to append a parameter to the url.

Is there a way to do this short of hand writing it on every REST request across the app?

Fritz
  • 41
  • 1

1 Answers1

0

I had similar problem in my current project.

To solve the problem I manually request current user info before app bootstapping & store it in localStorage.

Then bootstrap the app & in the config section you will have accesss to current user info.

TIP: to get user info before app bootstrap you can still use $http service by manually injecting it:

 angular.injector(['ng']).get('$http');
Alexey
  • 1,257
  • 7
  • 13