58789: Fix AuthenticatedGuard and put on higher level route

This commit is contained in:
Kristof De Langhe
2019-01-24 10:20:18 +01:00
parent 826830ca07
commit 552dce0960
3 changed files with 4 additions and 5 deletions

View File

@@ -1,14 +1,12 @@
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { AuthenticatedGuard } from '../core/auth/authenticated.guard';
@NgModule({ @NgModule({
imports: [ imports: [
RouterModule.forChild([ RouterModule.forChild([
{ {
path: 'registries', path: 'registries',
loadChildren: './admin-registries/admin-registries.module#AdminRegistriesModule', loadChildren: './admin-registries/admin-registries.module#AdminRegistriesModule'
canActivate: [AuthenticatedGuard]
} }
]) ])
] ]

View File

@@ -2,6 +2,7 @@ import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { PageNotFoundComponent } from './pagenotfound/pagenotfound.component'; import { PageNotFoundComponent } from './pagenotfound/pagenotfound.component';
import { AuthenticatedGuard } from './core/auth/authenticated.guard';
@NgModule({ @NgModule({
imports: [ imports: [
@@ -13,7 +14,7 @@ import { PageNotFoundComponent } from './pagenotfound/pagenotfound.component';
{ path: 'items', loadChildren: './+item-page/item-page.module#ItemPageModule' }, { path: 'items', loadChildren: './+item-page/item-page.module#ItemPageModule' },
{ path: 'search', loadChildren: './+search-page/search-page.module#SearchPageModule' }, { path: 'search', loadChildren: './+search-page/search-page.module#SearchPageModule' },
{ path: 'browse', loadChildren: './+browse-by/browse-by.module#BrowseByModule' }, { path: 'browse', loadChildren: './+browse-by/browse-by.module#BrowseByModule' },
{ path: 'admin', loadChildren: './+admin/admin.module#AdminModule' }, { path: 'admin', loadChildren: './+admin/admin.module#AdminModule', canActivate: [AuthenticatedGuard] },
{ path: 'login', loadChildren: './+login-page/login-page.module#LoginPageModule' }, { path: 'login', loadChildren: './+login-page/login-page.module#LoginPageModule' },
{ path: 'logout', loadChildren: './+logout-page/logout-page.module#LogoutPageModule' }, { path: 'logout', loadChildren: './+logout-page/logout-page.module#LogoutPageModule' },
{ path: '**', pathMatch: 'full', component: PageNotFoundComponent }, { path: '**', pathMatch: 'full', component: PageNotFoundComponent },

View File

@@ -54,7 +54,7 @@ export class AuthenticatedGuard implements CanActivate, CanLoad {
private handleAuth(url: string): Observable<boolean> { private handleAuth(url: string): Observable<boolean> {
// get observable // get observable
const observable = of(true); const observable = this.store.pipe(select(isAuthenticated));
// redirect to sign in page if user is not authenticated // redirect to sign in page if user is not authenticated
observable.pipe( observable.pipe(