Angular-auth0 issues

Im using Angular 11.1.1 and auth0/auth0-angular 1.3.2 and having a few problems. Forewarning, I’m no Angular expert but am fumbling my way through enough to get by.

The first problem I have is that when I call this.auth.loginWithRedirect({returnTo: url}) the URL is never returned to, it just defaults to my root domain. Ideally I can make people login, and after authentication send them to**/somepath**. I can’t seem to find any concrete doco or examples where this works.

The second problem I’m trying to solve is getting the isAuthenticated status, user_id and user nickname just once so I can store a local flag to use in the rest of the application. I currently do this in a hack about way where after login returns control to my app, the appcomponent includes a service to wrap the AuthService and it sets a value in the constructor:

this.authSubscription = this.auth.isAuthenticated$.subscribe((authed:boolean) => {
  if(authed) {
      // set auth flag
this.userSubscription = this.auth.user$.subscribe((data:any) => {
    if(data != null) {
        // set nickname from data.nickname
this.auth.idTokenClaims$.subscribe((claims) => {
  if(claims != null) {
    //set user_id from claims.sub

The problem with this though is that when I change pages this gets subscribed again since its in the constructor so I’ve had to wrap that code in a condition that only calls it when you aren’t already authenticated. In a perfect world I can get a one off callback after login is successful so I can retrieve the data I need. Observables are giving me headaches too, so if someone could provide a code snippet to get these values from the observables just once that would be great. I’ve tried combinations of first(), pipe(), take() etc but either get compiler issues or something else.

The next issue i have is that the AuthService seems to be calling out to /authorize when I go to a new page. In my case sometimes it fails with a 400.

The last issue is that for some reason I can’t quite pinpoint, once a minute due to this library my page magically redirects to my homepage, I’m guessing because of some kind of redirect callback to my origin page. I know its auth0 because if I don’t include the service, everything is fine.

Some advice on the above would be awesome, as it’s doing my head in and preventing me from getting the rest of my app done.


Looks like the 400 error was caused by the background token check. I’ve set auth0 to use cacheLocation: 'localstorage' for now, and that stops the background polling causing the 400 and subsequent redirection to the home page.

Feedback on the redirect to a page following login would be nice. From what I can see you need to configure it at build time using redirect_uri, but then its static. I want it dynamic.