# Redirect URI issue after successful login with @auth0/auth0-angular

**URL:** <https://community.auth0.com/t/redirect-uri-issue-after-successful-login-with-auth0-auth0-angular/58111>\
**Category:** Get Help\
**Tags:** redirecturi, redirect, angular, login\
**Created:** [February 18, 2021, 9:18pm UTC](https://community.auth0.com/t/redirect-uri-issue-after-successful-login-with-auth0-auth0-angular/58111 "2021-02-18T21:18:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![noragrossman](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/noragrossman/32/12732_2.png) [@noragrossman](https://community.auth0.com/u/noragrossman)\
**Post date:** [February 18, 2021, 9:18pm UTC](https://community.auth0.com/t/redirect-uri-issue-after-successful-login-with-auth0-auth0-angular/58111/1 "2021-02-18T21:18:05Z")

</div>

Hi there,

I’ve been banging my head against the wall trying to figure out why my Angular app is automatically redirecting to root after momentarily visiting the correct redirectUri upon a successful login.

The flow I have is fairly simple; when a user asks to login, I record the current path in local storage before calling this.authService.loginWithRedirect(). I have my callback URL set to `/callback`, and a simple CallbackComponent routed to /callback:

```
@Component({
  selector: 'app-callback',
  templateUrl: './callback.component.html',
  styleUrls: ['./callback.component.scss']
})
export class CallbackComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
    console.log("In CallbackComponent");
  }
}

```

After a successful login, however, Auth0 correctly redirects to “/callback” (and prints the console log), but then several milliseconds later the app navigates to “/” no matter what I try. I found this issue that looks to be very similar, but no resolution was posted: [Redirect URI problem with Auth0-spa-js and Angular](https://community.auth0.com/t/redirect-uri-problem-with-auth0-spa-js-and-angular/38267). Any thoughts on what might be going on?

For reference, here is a simplified version of my `app-routing.module.ts`:

```
export const routes: Routes = [
  { path: 'callback', component: CallbackComponent },
  { path: '', component: HomePageComponent },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

```

SDK: @auth0/auth0-angular (v1.2.0)  
Angular v9.1.12  
Node v15.2.1

---

<div class="post-metadata">

**Author:** ![frederik.prijck](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/frederik.prijck/32/27014_2.png) [@frederik.prijck](https://community.auth0.com/u/frederik.prijck)\
**Post date:** [February 25, 2021, 10:06pm UTC](https://community.auth0.com/t/redirect-uri-issue-after-successful-login-with-auth0-auth0-angular/58111/2 "2021-02-25T22:06:39Z")

</div>

Hi.

It looks like what is happening is expected.  
Our Angular SDK is configured to work as follows:

- User initiates login by calling loginWithRedirect
- User is redirected to Auth0, including a redirectUri (in this case /callback)
- User is, after succesful authentication, redirected back to the provided redirectUri (in this case /callback)
- The callback URL is used only to process code and state in order to retrieve an actual token
- The user is then redirected again to /

However, if you want to not be redirected back to `/` in the very last step, but instead they want the user to end up at a different URL, they can do so by providing that information to `loginWithRedirect()` :

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

```

By doing that, in the very last step the SDK will not redirect the user back to `/` , but to `/some-url` instead (see [https://github.com/auth0/auth0-angular/blob/master/projects/auth0-angular/src/lib/auth.service.ts#L299](https://github.com/auth0/auth0-angular/blob/master/projects/auth0-angular/src/lib/auth.service.ts#L299)).

> I record the current path in local storage before calling this.authService.loginWithRedirect()

There is no need for doing this. If you provide that route to `{ appState: { target: ''}}`, our SDK will store it in Session Storage for you.

---

<div class="post-metadata">

**Author:** ![noragrossman](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/noragrossman/32/12732_2.png) [@noragrossman](https://community.auth0.com/u/noragrossman)\
**Post date:** [February 25, 2021, 10:34pm UTC](https://community.auth0.com/t/redirect-uri-issue-after-successful-login-with-auth0-auth0-angular/58111/3 "2021-02-25T22:34:02Z")

</div>

This is perfect, thanks so much! It would be great to get this added to the documentation somewhere, because I was definitely misunderstanding the purpose of `redirectUri` (specifically the last two bullet points you stated).

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [February 26, 2021, 1:54pm UTC](https://community.auth0.com/t/redirect-uri-issue-after-successful-login-with-auth0-auth0-angular/58111/4 "2021-02-26T13:54:58Z")

</div>

Thanks for providing that feedback!

---

<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:** [March 13, 2021, 1:55pm UTC](https://community.auth0.com/t/redirect-uri-issue-after-successful-login-with-auth0-auth0-angular/58111/5 "2021-03-13T13:55:09Z")

</div>

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