From 9465ca521a5ec36c1753aada8d99b4c0e5f7cc1b Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Wed, 3 Aug 2016 00:16:16 +0100 Subject: [PATCH] Fixed login flow --- app/pages/home/home.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/pages/home/home.ts b/app/pages/home/home.ts index b39372b..c66fa85 100644 --- a/app/pages/home/home.ts +++ b/app/pages/home/home.ts @@ -15,6 +15,9 @@ import {NeighboursService} from '../../services/neighbours.service'; export class HomePage implements OnInit { neighbours: Observable; + buttonTitle = "Login"; + _authInfo: any; + displayName: any; constructor(public navCtrl: NavController, private _af: AngularFire, private _neighboursService: NeighboursService) { @@ -23,13 +26,33 @@ export class HomePage implements OnInit { ngOnInit() { this._af.auth.subscribe((data) => { if (data) { + this.buttonTitle = "Logout"; this._af.auth.unsubscribe(); + if (data.auth.providerData[0].providerId === "twitter.com") { + this._authInfo = data.auth.providerData[0] + this.displayName = data.auth.providerData[0].displayName + } else if (data.github) { + this._authInfo = data.github + } else { + this._authInfo = data.auth || {} + this.displayName = data.auth.providerData[0].email + } } else { this._displayLoginModal(); } this.neighbours = this._neighboursService.getNeighbours(); }); } + + logoutClicked() { + if (this._authInfo && (this._authInfo.email || this._authInfo.providerId)) { + this._af.auth.logout(); + this._authInfo = null + this._displayLoginModal() + } else { + this._displayLoginModal() + } + } registerMe() { this._neighboursService.registerMe();