-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
325a362
commit e1ce96e
Showing
4 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'rxjs/add/operator/take'; | ||
import 'rxjs/add/operator/map'; | ||
import { Store } from '@ngrx/store'; | ||
import * as Auth from '../actions/auth'; | ||
|
||
export class AuthGuard { | ||
|
||
authenticated = false; | ||
|
||
constructor(public store: Store<any>) { | ||
|
||
this.store.take(1).subscribe(state => { | ||
this.authenticated = !!(state && state.auth && state.auth.status && state.auth.status.loggedIn); | ||
}); | ||
|
||
/** TODO: check how to initialize auth in the root state */ | ||
/** Desired way | ||
* | ||
* this.store.select(fromAuth.getLoggedIn).take(1).map(authed => this.authenticated = authed); | ||
*/ | ||
} | ||
|
||
/** Check if page can enter */ | ||
ionViewCanEnter() { | ||
|
||
/** Auth Guard is disabled for dev. uncomment the following to activate */ | ||
if (!this.authenticated) { | ||
this.store.dispatch(new Auth.LoginRedirect()); | ||
} | ||
|
||
return this.authenticated; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import { Component } from '@angular/core'; | ||
import { Store } from '@ngrx/store'; | ||
|
||
import { NotificationsPage } from '../notifications/notifications'; | ||
import { AuthGuard } from '../../auth/guard/auth-guard'; | ||
|
||
@Component({ | ||
templateUrl: 'admin.html' | ||
}) | ||
export class AdminPage { | ||
export class AdminPage extends AuthGuard { | ||
|
||
tabNotifications = NotificationsPage; | ||
tabUsers = NotificationsPage; | ||
tabBilling = NotificationsPage; | ||
tabTest = NotificationsPage; | ||
|
||
constructor() { | ||
constructor(public store: Store<any>) { | ||
super(store); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters