DEV Community

Cover image for Angular adding a token to each API request

Angular adding a token to each API request

Chris Bongers on October 25, 2020

Alright, so normally, when we are making API requests, we will need some kind of token to validate our request. In our case, we just learned how t...
Collapse
 
mohsen2014 profile image
Mohsen Emami

Thanks, @dailydevtips1
I have an issue with the inspector in angular. I use angular-aws-amplify to fetch the token.
angular-aws-amplify has a method that returns an observable. but I don't know how can use an observable method in the inspector. do you know?

Collapse
 
dailydevtips1 profile image
Chris Bongers

Hey Mohsen,

What do you mean with inspector in angular, like a visual studio plugin or chrome plugin?

Normally you should be able to subscribe to an observable anyway.

Like amplify.subscribe(res => { console.log(res) });

Collapse
 
banzyme2 profile image
ENDEESA

Where is the token stored? Localstorage or in memory as part of the currentUser object?

Collapse
 
dailydevtips1 profile image
Chris Bongers

Actually both, so in this example, it's stored in local storage, but the service is mostly based on memory itself to get the user object.
It will however get it initially from localStorage if it exists.