Problem:
Login status is lost after refreshing the Angular (v19) SPA. Still in localhost only. Some reports say this happens with social login and developer keys, but I’m using username and password.
I downloaded the sample angular app from the dashboard, under applications → quickstart, using the big “Download sample” button.
It has the same problem.
The /authorize call:
After logging in and refreshing, the network tab shows a http request is made automatically to:
https://{myAuth0AppDomainHere}/authorize?client_id={bunchOfParametersAndValuesHere}...
It responds with 200OK and a html-page that contains a script-tag. The script contains
var authorizationResponse = {"error":"login_required","error_description":"Login required"...etc
So maybe that was the intended response?
The network tab shows no further actions taken after this request concludes.
The console outputs nothing after “Angular is running in development mode”.
How I set up the sample app:
Configuring was easy in auth_config.json
, setting these correctly:
- domain (value from the application → settings)
- clientId (value from the application → settings)
- Audience (the API identifier from the application → APIs)
In environments/environment.ts I found another audience string, and replaced it with my api identifier.
Dashboard application config
- Allowed callback urls:
http://localhost:4200
- Allowed Logout urls:
http://localhost:4200
- Allowed Web origins:
http://localhost:4200
- Credentials->Application authentication set to “None”
- Disabled “Cross origin authentication” (Tried some changes, but problem remains)
- Everything else untouched
Running the sample app
Usin node v20.18.3
Starting it with npm install && npm start
Npm installs fine. The app builds and starts fine.
I visit the app and click “login”, this redirects me to the auth0 login page, as expected.
Logging in with my username and password, I’m sent back to the app.
Login was successful login, then I refresh the page with F5.
The login button is back, indicating that I’m not logged in.
Clicking it logs me back in after a brief window flash (presumably sending me to auth0 login page and back immediately).
So now what?
Is there more I can check? I tried following all the guides. I searched all the older topics. Asked all the GPTs. Tried simplifying the code until I was left with nothing but the problem.
How can I stay logged in after refreshing the Angular app?