# Auth0 Angular - Removing the state query parameter on Login redirect w/ error

**URL:** <https://community.auth0.com/t/auth0-angular-removing-the-state-query-parameter-on-login-redirect-w-error/121153>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [November 17, 2023, 9:15pm UTC](https://community.auth0.com/t/auth0-angular-removing-the-state-query-parameter-on-login-redirect-w-error/121153 "2023-11-17T21:15:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Auth0.user](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Auth0.user](https://community.auth0.com/u/Auth0.user)\
**Post date:** [November 17, 2023, 9:15pm UTC](https://community.auth0.com/t/auth0-angular-removing-the-state-query-parameter-on-login-redirect-w-error/121153/1 "2023-11-17T21:15:41Z")

</div>

After a successful authentication, a user can fail to authorize because their account is blocked or for various other reasons like an action.  
When this happens the redirect url contains the error and state query parameters.  
ex:  
`?error=unauthorized&error_description=user%20is%20blocked&state=Y0lWcndGcE9rbDVZdXl3M1BWbEFUOXZ5YnFkYmlXUjJNTHM2OE9Gc0lYTQ%3D%3D`

Expected: The application at the URL redirect has an opportunity to handle these parameters and display a message saying why the login failed and what to do.

Actual: Because there is a token in the query parameter, Auth0 Angular redirects us to the base route `/` without even fully loading the page.

* * *

Questions:

- Why does the url contain an empty token on a failure to authorize?
- How can I show a message to the user saying they have been blocked if Auth0 Angular is automatically redirecting to the base route due to there being a state query parameter with an invalid token?

P.S. Sorry if the tags are wrong, there’s a limited selection and it requires 2 to post.

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [November 20, 2023, 12:48pm UTC](https://community.auth0.com/t/auth0-angular-removing-the-state-query-parameter-on-login-redirect-w-error/121153/2 "2023-11-20T12:48:56Z")

</div>

Hey there @Auth0.user ,  
Thank you for posting.

- The `state` URL [parameter](https://auth0.com/docs/secure/attack-protection/state-parameters) its just a value being created during the initial step of the authorization process (by the client app) to ensure the requests happen between the same IdP and a client app (the client app expects the state value received in a response from the IdP to be the same as it’s initially generated).

```auto
http://tenant.auth0.com/authorize?...&state=xyzABC123

```

- `How can I show a message to the user saying they have been blocked`  
This doc can put some light on it. Unfortunately, currently there is no way to adjust the flow. There is also some suggestion there for a [workaround](https://community.auth0.com/t/redirect-blocked-users-to-a-custom-error-page-using-rules-or-actions/99087).

This [topic](https://community.auth0.com/t/render-a-custom-error-page-from-rule/61010/3) refers to a similar problem.  
The [doc](https://auth0.com/docs/customize/universal-login-pages/custom-error-pages) describes scenarios where Auth0 redirect to a default or custom error pages.

I hope it helps!

---

<div class="post-metadata">

**Author:** ![Auth0.user](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Auth0.user](https://community.auth0.com/u/Auth0.user)\
**Post date:** [November 20, 2023, 10:04pm UTC](https://community.auth0.com/t/auth0-angular-removing-the-state-query-parameter-on-login-redirect-w-error/121153/3 "2023-11-20T22:04:48Z")

</div>

That’s all well and good… **BUT** Auth0 Angular SDK automatically redirects to the base route `/` whenever these query parameters are present on any route:  
?code=abc123&state=abc123

To reiterate the issue:  
If auth0/auth0-angular is instantiated in an Angular application at all, then any route with those query parameters will automatically route the page back to the base route as soon as it loads which is before any angular component can even be loaded.

Unless there is a way to exempt pages from getting redirected whenever the above query parameters are specified, this is an issue with Auth0 Angular itself.

- If you need a stackblitz implemented with Auth0 to further understand the issue, I can provide that.
- If you need me to instead open an issue on the github for Auth0 Angular, I can do that.

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [November 21, 2023, 8:45am UTC](https://community.auth0.com/t/auth0-angular-removing-the-state-query-parameter-on-login-redirect-w-error/121153/4 "2023-11-21T08:45:28Z")

</div>

Hi @Auth0.user ,

I saw here in the community some confusion around redirecting a user back to other than the root url destination after a successful authentication with auth0/auth0-angular.

If you intend to provide a specific URL to direct the user to after the login flow ends, the LoginWithRedirect method’s options serves it - [AuthService | @auth0/auth0-angular](https://auth0.github.io/auth0-angular/classes/AuthService.html#loginWithRedirect).

```auto
loginWithRedirect({
  appState: { target: '/some-url' }
})

```

Here is another topic’s discussion around it that potentially can help - [Redirect URI issue after successful login with @auth0/auth0-angular](https://community.auth0.com/t/redirect-uri-issue-after-successful-login-with-auth0-auth0-angular/58111).

I hope this will help, but if not, the [repo’s feedback / issues section](https://github.com/auth0/auth0-angular/tree/main#contributing) is open for contribution.

---

<div class="post-metadata">

**Author:** ![Auth0.user](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Auth0.user](https://community.auth0.com/u/Auth0.user)\
**Post date:** [November 21, 2023, 3:04pm UTC](https://community.auth0.com/t/auth0-angular-removing-the-state-query-parameter-on-login-redirect-w-error/121153/5 "2023-11-21T15:04:29Z")

</div>

As stated previously, this is specifically on a failed authentication. This actually redirects me to the custom error page URL you pointed me towards with your first response and not the url within login with redirect.

This happens to be the same page on our application, however even with the custom error page having the same url as specified in the loginWithRedirect, the application still redirect back to `/` if Auth0 is instantiated.

I will post to the Github in hopes they actually take the time to understand the issue instead of just responding with the best approximate documentation or existing issues.

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [November 21, 2023, 4:11pm UTC](https://community.auth0.com/t/auth0-angular-removing-the-state-query-parameter-on-login-redirect-w-error/121153/6 "2023-11-21T16:11:02Z")

</div>

Hi @Auth0.user ,

Apologies for any confusion here!

Looking at the doc I shared on [error / custom error pages](https://auth0.com/docs/customize/universal-login-pages/custom-error-pages), these are served when there is an error during the authentication, like incorrectly formed `/authorization` request / invalid callback URL or an expired login link in case of a Classic Login Page instead of correctly handled login rejection due to a user being blocked.

The specification I shared regarding setting a path for the callback URL `root/what_comes_next` was in case you decide to try the mentioned before [workaround](https://community.auth0.com/t/redirect-blocked-users-to-a-custom-error-page-using-rules-or-actions/99087), just I see now the link has not been attached (basically it refers to not to block a user causing a login rejection but to use actions based on a usermetadata value).

But whenever you find the specification / docs are in contradiction to what you observe, reaching out directly to the repo owners seems to be most efficient way.

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [November 21, 2023, 7:12pm UTC](https://community.auth0.com/t/auth0-angular-removing-the-state-query-parameter-on-login-redirect-w-error/121153/7 "2023-11-21T19:12:10Z")

</div>

If applicable, the issues section for the repo - [Issues · auth0/auth0-angular · GitHub](https://github.com/auth0/auth0-angular/issues).

---

<div class="post-metadata">

**Author:** ![Auth0.user](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Auth0.user](https://community.auth0.com/u/Auth0.user)\
**Post date:** [November 27, 2023, 6:14pm UTC](https://community.auth0.com/t/auth0-angular-removing-the-state-query-parameter-on-login-redirect-w-error/121153/8 "2023-11-27T18:14:55Z")

</div>

The solution to this issue was setting the `errorPath` in the AuthModule app.module configuration.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 11, 2023, 6:15pm UTC](https://community.auth0.com/t/auth0-angular-removing-the-state-query-parameter-on-login-redirect-w-error/121153/9 "2023-12-11T18:15:29Z")

</div>

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