I am trying to find a solution that will redirect to the authorization endpoint before loading the angular first (html and components). Is that even possible? Or is it possible to use CanActivate auth guard on my main app.component?
I am using an auth guard, just like any other angular projects. But it first loads the html first before redirecting to the authorization endpoint.
Here's what I've done so far :
(My Routing Component)
const routes: Routes = [
{
path: '',
redirectTo: 'main',
pathMatch: 'full',
canActivate: [AdminRouteGuard]
},
{
path: 'main',
component: MainComponent,
canActivate: [AdminRouteGuard]
},
{
path: '**',
redirectTo: 'main',
pathMatch: 'full',
canActivate: [AdminRouteGuard]
}];
(My Route Guard)
export class AdminRouteGuard implements CanActivate {
constructor(@Inject(DOCUMENT) private document: any, private _authService: AuthService, private router: Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this._authService.isLoggedIn()) {
return true;
}
else {
return this._authService.login();
}}}