Created
June 25, 2018 23:20
-
-
Save haverchuck/45d0d6195091bf570eb6d7dcc8dc6cf5 to your computer and use it in GitHub Desktop.
ionic-amplify-part-3
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 { Component, AfterContentInit } from '@angular/core'; | |
import { Events } from '@ionic/angular'; | |
import { AuthGuardService } from '../../services/auth-route-guard' | |
import { AmplifyService } from 'aws-amplify-angular'; | |
@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 | |
amplifyService: AmplifyService | |
constructor( | |
public events: Events, | |
public guard: AuthGuardService, | |
public amplify: AmplifyService | |
) { | |
this.authState = {loggedIn: false}; | |
this.authService = guard; | |
this.amplifyService = amplify; | |
this.amplifyService.authStateChange$ | |
.subscribe(authState => { | |
this.authState.loggedIn = authState.state === 'signedIn'; | |
this.events.publish('data:AuthState', this.authState) | |
}); | |
} | |
ngAfterContentInit(){ | |
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