Skip to content

Instantly share code, notes, and snippets.

@haverchuck
Created June 25, 2018 20:57
Show Gist options
  • Save haverchuck/c51d864b9d1b67d7b95162e92298d64b to your computer and use it in GitHub Desktop.
Save haverchuck/c51d864b9d1b67d7b95162e92298d64b to your computer and use it in GitHub Desktop.
ionic-amplify-part-1
import { Component, AfterContentInit } from '@angular/core';
import { Events } from '@ionic/angular';
import { AuthGuardService } from '../../services/auth-route-guard'
@Component({
selector: 'app-page-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss']
})
export class HomePage implements AfterContentInit{
authState: any;
// including AuthGuardService here so that it's available to listen to auth events
authService: AuthGuardService
constructor(public events: Events, public guard: AuthGuardService) {
this.authState = {loggedIn: false};
this.authService = guard;
}
ngAfterContentInit(){
this.events.publish('data:AuthState', this.authState)
}
login() {
this.authState.loggedIn = true;
this.events.publish('data:AuthState', this.authState)
}
logout() {
this.authState.loggedIn = false;
this.events.publish('data:AuthState', this.authState)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment