I have an angular page using angular-oauth2-oidc with Keycloak OIDC implicit flow.
After logging in with Keycloak, it will get redirected back to the landing page. The landing page [app.component.html] will then check with allowAccess() for valid tokens to display main-nav or app-cover accordingly.
From my understanding because this validation takes a small amount of time, so while checking these tokens, the landing page will first display app-cover and then quickly change to main-nav.
This behavior seems to provide a bad user experience, since the landing page flickers for a brief second before redirecting to main-nav. Is there a way I could inject a loading page or delay while getting these validations? Is there a problem with this conditional routing that causes this issue?
Or what is the best practice when switching b/w components?
Thanks
[app.component.html]
<main-nav *ngIf="allowAccess">
<router-outlet></router-outlet>
</main-nav>
<app-cover *ngIf="!allowAccess"></app-cover>
[app.component.ts]
import { OAuthService, JwksValidationHandler} from 'angular-oauth2-oidc';
import { authConfig } from './auth.config';
import { Component } from '@angular/core';
export * from './auth/auth.guard.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(private oauthService: OAuthService) {
this.configureWithNewConfigApi();
}
private configureWithNewConfigApi() {
this.oauthService.configure(authConfig);
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService.loadDiscoveryDocumentAndTryLogin();
}
public get allowAccess() {
return this.oauthService.hasValidAccessToken();
}
}
[routing module]
RouterModule.forRoot([
{ path: '', component: HomeComponent },
{ path: 'notification', component: NotificationComponent, canActivate: [AuthGuard] },
{ path: 'settings', component: SettingsComponent, canActivate: [AuthGuard] },
]),