Created
June 19, 2018 16:23
-
-
Save haverchuck/46262f0c03626d9fcaa5829728b355c9 to your computer and use it in GitHub Desktop.
ionic-amplify-part-1: auth-guard
This file contains hidden or 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
import { Injectable } from '@angular/core'; | |
import { Router, CanActivate } from '@angular/router'; | |
import { Events } from '@ionic/angular' | |
@Injectable() | |
export class AuthGuardService implements CanActivate { | |
signedIn: boolean; | |
constructor(public router: Router, public events: Events) { | |
this.events.subscribe('data:AuthState', async (data) => { | |
if (data.loggedIn){ | |
this.signedIn = true; | |
} else { | |
this.signedIn =false | |
} | |
}) | |
} | |
canActivate() { | |
return this.signedIn; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment