Angular 7 - On page refresh/new tab, auth is lost and requires user to click login

Hi @arl

Looks like the Angular QuickStart was updated so things are a little different to what I remember.

From what I can see in the new QuickStart you may be able to modify the code in the AppComponent.

In the ngOnInit function, change the following lines of code:

    if (this.auth.isAuthenticated()) {
      this.auth.renewTokens();
    }

to

    this.auth.renewTokens();

What this will do is always execute your renewTokens() function when the app initializes which in turn calls the checkSession() function in the auth0-js library which checks to see if there is a valid Auth0 session for the user and if so will return you with a new access_token.

You may need to play around with a few different options / order of checks and operations depending on your needs.

Hope this helps!

1 Like