Fixed login flow

This commit is contained in:
Fergal Moran
2016-08-03 00:16:16 +01:00
parent 39943ef427
commit 9465ca521a

View File

@@ -15,6 +15,9 @@ import {NeighboursService} from '../../services/neighbours.service';
export class HomePage implements OnInit {
neighbours: Observable<any[]>;
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();