Skip to content

Instantly share code, notes, and snippets.

@haverchuck
Created June 19, 2018 16:23
Show Gist options
  • Save haverchuck/46262f0c03626d9fcaa5829728b355c9 to your computer and use it in GitHub Desktop.
Save haverchuck/46262f0c03626d9fcaa5829728b355c9 to your computer and use it in GitHub Desktop.
ionic-amplify-part-1: auth-guard
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