0

I have appSetting.js file that contain code like

var appSettings = {
    oauth: {
        issuer: 'https://sts.windows.net/.../',
        resource: 'api://...',
        clientId: 'd44fewd3-xyzw',
        logoutUrl: window.location.origin + '/index.html',
        redirectURI: window.location.origin`enter code here`
    }
};

and authConfig.ts file like this

import { AuthConfig } from 'angular-oauth2-oidc';
import { environment } from 'src/environments/environment';

export const authConfig: AuthConfig = {

   // issuer:  'https://sts.windows.net/xyz/', //this (static value) line is working for unit test case fine
   issuer: (window as any).appSettings.oauth.issuer, // but this (dynamic value) line is not working
   
    // clientId: 'd44fewd3-xyzw',
    clientId: (window as any).appSettings.oauth.issuer,

    
};

it throw error like this.

How to make authConfig file keys dynamic? enter image description here

user547534
  • 70
  • 8
  • This appSetting.js file seems really weird and uncommon, what is the use of it? Why don't you provide the settings directly in authConfig.ts file? – MoxxiManagarm Oct 22 '20 at 12:54
  • @MoxxiManagarm we have different environments like dev, uat and prod for this we have 3 separate appSetting files .for short I have just post the appSeeting file – user547534 Oct 22 '20 at 12:57
  • I still don't really see the use here. You could also provide several authConfig files or even define the constant in the environment.ts files. If that all is not valid for you, you should consider importing the js file to the ts file as described here instead of refering to the window object. https://stackoverflow.com/questions/41219542/how-to-import-js-modules-into-typescript-file – MoxxiManagarm Oct 22 '20 at 13:02

0 Answers0