Configuring the Angular router to `useHash: true` breaks `OktaAuthService.loginRedirect`

When I click the login button provided in the quickstart I get this error after a redirect from the /implicit/callback route:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'code'
Error: Cannot match any routes. URL Segment: 'code'
    at ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirects.noMatchError (router.js:2459)
    at CatchSubscriber.selector (router.js:2440)
    at CatchSubscriber.push../node_modules/rxjs/_esm5/internal/operators/catchError.js.CatchSubscriber.error (catchError.js:34)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:79)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:59)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:79)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:59)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:79)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:59)
    at ThrowIfEmptySubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:79)
    at resolvePromise (zone.js:836)
    at resolvePromise (zone.js:795)
    at zone.js:897
    at ZoneDelegate.invokeTask (zone.js:431)
    at Object.onInvokeTask (core.js:26246)
    at ZoneDelegate.invokeTask (zone.js:430)
    at Zone.runTask (zone.js:198)
    at drainMicroTaskQueue (zone.js:611)

I’m not testing this in a new empty app, it will be my next step to see if it also occurs in an empty project, strictly following the quickstart guide, but what could be the issue here? Nowhere in my project do I refer to any ‘code’ paths and it seems to happen during the process that I import straight from OktaAuthModule.

The entry point into that module is this call:

this.oktaAuth.loginRedirect('/home');

where this.oktaAuth is the OktaAuthService

It’s a bug! :bug:

It occurs if you set useHash: true on the router.

RouterModule.forRoot(routes, {
  useHash: true
})

I’ve made a StackBlitz example that reproduces the issue https://stackblitz.com/edit/angular-5bkkhr (just plug your credentials in the config in app.module.ts). I accept any and all symbolic rewards such as badges and bragging rights for my find. In absence of any such swagger my next bug report will go no further than: “it no worky worky, plz help”.

The stackblitz doesn’t work when you try it through the preview panel on the right but it will work if you visit the stackblitz’s standalone page.

We have the same issue, on a new Application. Issue was reported on December. Do we have any feedback on this issue? Any ideas for fixing the problem?

Quit important as we need to move our existing App from Cognito AWS to OKTA, thus we need to find a solution.

Thanks in advance for any feedback!

This was a real pain in the butt!! But, I have a bare bones working example of how to resolve this issue available on github. You need to intercept the route via CanActivate and use @okta/okta-auth-js tokenManager instead of @okta/okta-angular CallbackComponent.

If my github repo saved your life (or maybe your day/week) please star it :slight_smile:

Credits:I figured this out with a little help from https://github.com/okta/okta-oidc-js/issues/672 . Also Matt Raible made himself available for my first round of debugging/sanity checking questions https://www.okta.com/blog/author/matt-raible/