Q:

Auth0 Callback URL Live and Development

I currently have an Angular 2 App that uses Auth0 to do authentication. Everything is working fine, but the callback url in the login service only works for the live website. So when I am running my development code on localhost and go to login it always redirects me to the live version of my website, I don't want to have to keep changing one line of code back and forth between my deployments and when I am testing locally. Here is the login method in the auth.service.ts.
public login(): void {

this.auth0.authorize({
  responseType: 'token id_token',
  audience: 'https://xxxxxx/userinfo',
  redirectUri: 'http://www.mylivewebsite.com/callback',      
  scope: 'openid'
});

I use this when I am testing the app locally.
public login(): void {

this.auth0.authorize({
  responseType: 'token id_token',
  audience: 'https://xxxxxx/userinfo',
  redirectUri: 'http://localhost:4200/callback',      
  scope: 'openid'
});

Is there a way to detect what URL I came from and adjust accordingly? I feel like there is a simple answer but I cant seem to find a way to make it work.

A:

The way that I handle this is with an environment variable. Many people will use the NODE_ENV to determine if an app is in development or production.
You could do this:
public login(): void {

this.auth0.authorize({
  responseType: 'token id_token',
  audience: 'https://xxxxxx/userinfo',

  redirectUri: (process.env.NODE_ENV === 'production') ? [deploy url] : [dev url],

  scope: 'openid'
});

