From 3877cd60b278f14e2997ea9b29105b085504ef9d Mon Sep 17 00:00:00 2001 From: Mario Romano Date: Wed, 2 Nov 2016 01:13:53 +0000 Subject: [PATCH] redirect to login page not loggedin users --- demo-shell-ng2/app/app.component.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/demo-shell-ng2/app/app.component.ts b/demo-shell-ng2/app/app.component.ts index 2f89a4f6da..ad1a1365aa 100644 --- a/demo-shell-ng2/app/app.component.ts +++ b/demo-shell-ng2/app/app.component.ts @@ -51,11 +51,18 @@ export class AppComponent { } isLoggedIn(): boolean { + this.redirectToLoginPageIfNotLoggedIn(); return this.auth.isLoggedIn(); } + redirectToLoginPageIfNotLoggedIn(): void { + if (!this.isLoginPage() && !this.auth.isLoggedIn()) { + this.router.navigate(['/login']); + } + } + isLoginPage(): boolean { - return location.pathname === '/login' || location.pathname === '/'; + return location.pathname === '/login' || location.pathname === '/' || location.pathname === '/settings'; } onLogout(event) {