The Complete Guide to Angular User Authentication with Auth0

You rock! Thank you for the follow up. Hope your break was great, Happy New Year!

1 Like

When I press the buttons to get the public/private messages both return nothing. Could it be that my API does not have that in scope? How can I utilize this same function to call from my audience domain something like /api/v2/users (returns all users)?

My is “http://localhost:6060” and I have setup an
“audience”: “”.

The service is apparently found but I can’t figure out how to call the scopes. Thanks!

Great article, thanks! One question: What happens, when the Access Token expires? Does the AuthService also handle token refreshes?

1 Like

Yes, it does! Whenever you call the getTokenSilently method, you get a new fresh access token :medal_sports:

Howdy, Rick! Welcome to the Auth0 Community and thank you for reading this blog post.

I’d like to better understand your question :slight_smile: Are you trying to access the /user endpoint of the Auth0 Management API from your client application?

It was much needed rest :slight_smile: Happy New Year to you as well!

Thanks for the quick reply! Sounds good as long as the user is logged in, but when the token expires while the user is currently not on the website or offline, they will be logged out, right? Is there a way to implement “stay logged in” with that? AFAIK that would require storing a long-lived refresh token somewhere locally, right? :confused:

Hi all,

I’m trying to learn how to create authentiaction for a Angular SPA.

I’ve completed the great tutorial at The Complete Guide to Angular User Authentication with Auth0, and most of it worked very well out of the box.

But every time I refresh the page, I have to login again. I think it’s a very basic requirement not to have to login every single time, but the blog post says absolutely nothing about this topic. Even worse, when I tried to google the solution, I found problems concerning disabling auto login, but not a single tutorial about enabling it. So I think it must be my fault. Perhaps it is enabled by default and I simply did something wrong.

So can you give me a simple pointer what I have to do to keep the user signed in?




Thanks for raising this! I migrated your topic to this thread as this one is strictly related to the blog post you mentioned and you’ll be able to get help on that here!

Hi @dan-auth0, I’m having the same problem that @phortonssf described, do you have any solutions for that?

1 Like

Sorry for the delay on getting that up and running. I’ve been dealing with some post-holiday deadlines and such. I’m looking to create a code sample on that implementation and I’ll share it with y’all here.

1 Like

Do you want to always redirect authenticated users to /profile?

@phortonssf @hamid.behnam

This PR addresses the following use case:

When you have an Angular application page with mixed access (the page renders components to both unauthenticated and authenticated users) you want the users to come back to the same page after they log in or log out.

For example:

/external-api renders resources for public and authenticated users. After a user logs in by clicking the “Log In” button on the navigation bar, the user should return to /external-api after the user logs in with Auth0 – not the home page, /.

If the user log outs from this page, the user should return to this page as well.

Please read the README of the PR for details on how to run it. You can clone the repo and checkout the secure-backlinks branch, please. :pray:

Note: This PR is based on the end-result of following the guide of this topic. The diff shows the changes I made to implement the use case.


Howdy, Robin! What’s the use case that you are looking to cover for the user to stay logged in while the user is offline? Also, to better assist you on this topic, I’d like to suggest if you open a topic for this particular support case :)That way we can have a more detail conversation in that topic and also it gets more visibility with other Auth0 teammates :slight_smile:

You can open the topic under our General board and tag me :+1:

1 Like

@phortonssf Checkout this PR to see how to always take the user to the /profile page after login if and only if the user initiates the login transaction using a login button:

If the user clicks on a route that you are protecting using AuthGuard, the user will go to the page they were trying to access before being prompted to log in.

Are you trying to also route users to /profile always always, even when using AuthGuard?

Note: This PR is based on the end-result of following the guide of this topic. The diff shows the changes I made to implement the use case.


This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

I have to give credit when credit is due.
Hands down && tip my hat && raise a glass to you sir… one of the best tutorials I’ve gone through. Lots of well linked articles, great source of info.

Authentication seems like such a daunting task, but this really does 99.9% of the heavy lifting for you.

Saved so much time! I did a bit of research on building in-house authentication from scratch (FML). Your services saved a googol of time :laughing: and finished this tutorial just as I finished my second drink :sunglasses:



Kudos @dan-auth0 !!! :tada::tada::tada::tada::tada::tada:

1 Like


When I call the external api I encounter an CORS issue.

I follow the tutorial to open up the express server at localhost:6060 and the angular server at localhost:4200.

The callApi method in angular is as in the tutorial:

callApi(): void {
.subscribe((result: Message) => {
this.message = result.message;

The serverUrl is also set to http://localhost:6060 as in the turorial.

Cound anyone help me? Thank you!