0
votes

I am trying to login using Auth0 from Angular2 app. The code is derived from Auth0 sample. It was working but now the behavior is a bit weird.

Token data appended to the url:

http://localhost:4200/#access_token=0ZoQ3U6Ma2tAhQnh&id_token=eyJ0e...jqd&token_type=Bearer

event authenticated did not raise:

@Injectable()
export class Auth0Service {

  // Configure Auth0
  lock = new Auth0Lock('I21EAjbbpfPh...', 'xxx.au.auth0.com', {});

  constructor() {
    // Add callback for lock `authenticated` event
    this.lock.on("authenticated", (authResult) => {
      // Use the token in authResult to getProfile() and save it to localStorage
      this.lock.getProfile(authResult.idToken, function(error, profile) {
        if (error) {
          // Handle error
          return;
        }

        localStorage.setItem('id_token', authResult.idToken);
        localStorage.setItem('profile', JSON.stringify(profile));
      });
    });
  }
...

Any idea pls?

1

1 Answers

1
votes

LocationStrategy and HashLocationStrategy are added to resolve routing url probblem when refreshing the page however it causes issue to Auth0 function.

Removing them in app.module.ts to get Auth0 function back.

//{provide: LocationStrategy, useClass: HashLocationStrategy},