import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class SessionStorageService {
setItem(key: string, value: any) {
sessionStorage.setItem(key, JSON.stringify(value?.access_token));
}
getItem(key?: string): any {
const item = sessionStorage.getItem(key);
return item ? JSON.parse(item) : null;
}
}
and this the congif file:
import { SessionStorageService } from './session.service';
const authConfigService = new SessionStorageService();
const authToken = authConfigService.getItem();
console.log(authToken);
export const authConfig = {
authToken: authToken
};
and finally here is proxy.conf.js
const { authConfig } = require('./config');
module.exports = [
{
context: ['/v1/**'],
target: defaultTarget,
changeOrigin: true,
headers: { "Authorization": `Bearer ${authConfig.authToken}` }
}
];