In my coding project, I am encountering an issue where the header authorization (Bearer + token) is not being set properly. Although there is a variable called token stored in my localstorage, when I print it, the bearer part appears to be null.
Here is the code snippet from auth.services.ts:
getToken() {
const token = localStorage.getItem('token');
console.log(token);
return token;
}
And here is the code snippet from token-interceptor.ts:
constructor(private authService: AuthService) { }
intercept(req, next) {
const tokenizeReq = req.clone({
setHeaders: {
authorization: `Bearer ${this.authService.getToken()}`
}
});
return next.handle(tokenizeReq);
}
When checking the console outputs,
https://i.sstatic.net/lAJKX.png
I have also examined the Network variables and LocalStorage contents,
The issue appears to be with setting 'null'. Any insights on why this is happening would be greatly appreciated.