I have auth.service.ts file that fetchs the access token
auth.service.ts
public async getAccessToken(): Promise<string | undefined> {
await this.initialize();
const res = await this.getAuthResult();
this.bearerToken = res?.accessToken;
return res?.accessToken;
}
I have been able to import the auth token to other pages using
import { AuthService } from '../../services/auth/auth.service';
async getToken() {
await this.auth.getAccessToken();
console.log("token", this.auth.bearerToken);
}
What I am trying to do is import this token into the 'x-authorization-token' in the environment.ts file if possible
environment.ts
import { HttpHeaders } from '@angular/common/http';
import { AuthService } from '../app/services/auth/auth.service';
export const environment = { production: false };
export const headerAuth: any = {
headers: new HttpHeaders({
'x-authorization-token': '', // To be imported from Auth Service
'access-control-allow-origin': 'https://XXXXX.fred.com/',
'access-control-allow-methods': 'GET,POST,OPTIONS',
'access-control-allow-headers': 'Content-Type, X-Authorization-Token, Origin',
'content-type': 'application/json',
})
}