Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set Bearer token #38

Closed
mackelito opened this issue Mar 6, 2017 · 3 comments
Closed

How to set Bearer token #38

mackelito opened this issue Mar 6, 2017 · 3 comments

Comments

@mackelito
Copy link

I have a service where I have a getToken() method.
getToken uses localforage to get it form localstorage (https://localforage.github.io/localForage/#data-api-getitem)

getToken() {
  return localforage.getItem('auth', function (err, value) {
    return _.result(value, ['access_token']);
  });
}

But I have the problem where the componets I have makes requests before the token is set.
I have tried to use RestangularProvider.addFullRequestInterceptor but have the same issue there.

So what is the proper way to first get the token from the API and then set it to the defaultHeaders?

@logvinoleg89
Copy link
Collaborator

Hi @mackelito, you can use addFullRequestInterceptor method. I have updated documentation, please follow link

@mackelito
Copy link
Author

I solved this by setting up a AuthGuard instead... perhaps that was a bad approach?

@logvinoleg89
Copy link
Collaborator

In my opinion it's better to use AuthGuard by its initial purpose white to set Bearer token I would use addFullRequestInterceptor method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants