Angular. Environment variable issuer must be set

Hi all! I am studying samples-js-angular and always get the same error:
An unhandled exception occurred: Environment variable ISSUER must be set. See README.md
I tried to put Client_Id and Issuer in environment.ts like this:

export const environment = {
  production: false,
  ISSUER: "https://dev-843586.okta.com/oauth2/default",
  CLIENT_ID: "0oa48iu3oCyIWyO3I4x6"
};

It did not work.
Then I tried to put them in app.config.ts like this:

export default {
  oidc: {
    clientId: "0oa48iu3oCyIWyO3I4x6",
    issuer: "https://dev-843586.okta.com/oauth2/default",
    redirectUri: 'http://localhost:8080/implicit/callback',
    scopes: ['openid', 'profile', 'email'],
    testing: {
      disableHttpsCheck: `${OKTA_TESTING_DISABLEHTTPSCHECK}`
    }
  },
  resourceServer: {
    messagesUrl: 'http://localhost:8000/api/messages',
  },
};

It did not help either.
I still get the same error in terminal.
What do I do wrong? Could anybody help me?

Hi @TermenVox

Can you please add a file called testenv (without any extensions) in the root directory (not inside /custom-login or /okta-hosted-login) with the following values:

ISSUER=https://your-okta-org-here.okta.com/oauth2/default
CLIENT_ID=your-client-id-here
1 Like

Thank you very much! It works!

1 Like

testenv with no extension at all doesnt seem to work for me? I get same error

Check if your testnv file is in the correct folder.
For example, if your angular components are in the following route:
D:\Programming\mega_project\okta_test\src\app
then your package.json file lays in okta_test folder and testnv file must be in the mega_project folder.
If you doubt - put testnv in all folders :grinning:
Or just use workaround - in app.config.ts remove the following string
const { CLIENT_ID, ISSUER, OKTA_TESTING_DISABLEHTTPSCHECK } = process.env;
and hardcode your client id and issuer in the oidc object. Something like this:

export default {
  oidc: {
    clientId: "0oa48iu3oCyIWyO3I4x6",
    issuer: "https://dev-843586.okta.com/oauth2/default",
    redirectUri: 'http://localhost:8080/implicit/callback',
    scopes: ['openid', 'profile', 'email'],
  },
  resourceServer: {
    messagesUrl: 'http://localhost:8000/api/messages',
  },
};