I have an Angular 9 app using the latest Okta Angular npm package. The app is hosted at /app (ie base URL is not /) and has routes protected with OktaAuthGuard.
After the auth happens, the redirect from the callback route (/app/implicit/callback) always goes to /, which of course is the wrong page. However, if I manually go to the correct URL prefixed with /app, everything is good and I am logged in.
How can I make the OktaAuthGuard redirects correctly honor the base href or otherwise work around this?
The solution I came up with was to create a duplicate OktaAuthGuard in my project. You can then inject PlatformLocation and use getBaseHrefFromDOM(). Prepend this to state.url. State.url is relative to the root router URL so it really shouldn’t be used as the URL that gets passed to an external service.
this.oktaAuth.setFromUri(state.url);
Becomes (use whatever pathJoin function suits you):