Search code examples
angularangular-builderangular-config

Angular configuration for dev/prod


I use Auth0 service which provides me two client_id's - for development and for production. However, this has to be built-in source code:

@Injectable({
  providedIn: 'root'
})
export class AuthService {
  // Create an observable of Auth0 instance of client
  auth0Client$ = (from(
    createAuth0Client({
      domain: 'xxxxx',
      client_id: 'Mx9x.........',
      redirect_uri: `${window.location.origin}/authorize`,
      audience: 'xxxx'
    })
  ) as Observable<Auth0Client>).pipe(
    shareReplay(1), // Every subscription receives the same shared value
    catchError(err => throwError(err))
  );

I would love to use one during local development and another for production built. Is this doable? Thanks!


Solution

  • You can Use environment.ts for development config/keys and environment.prod.ts for production config/keys , where during build when using ng build --prod angular replace environment.ts with environment-prod.ts