Skip to content

Instantly share code, notes, and snippets.

@javebratt
Created March 21, 2017 16:49
Show Gist options
  • Save javebratt/ecb8f46c35bf73d4fd93016ba35d1ccd to your computer and use it in GitHub Desktop.
Save javebratt/ecb8f46c35bf73d4fd93016ba35d1ccd to your computer and use it in GitHub Desktop.
// You can create a function in your authentication provider that resolves the value of admin:
isAsdmin(): Promise<any> {
return new Promise( (resolve, reject ) => {
firebase.database().ref(`userProfile/${userId}/admin`).once('value', adminSnapshot => {
resolve(adminSnapshot.val());
});
});
}
// That will return wither tru or false, then you call it from the class:
constructor(public navCtrl: NavController, public authData: AuthData) {
authData.isAsdmin().then( adminStatus => {
this.isAdmin = adminStatus;
});
}
// Then is just a matter of calling it inside the html:
<ion-content padding>
<div *ngIf="isAdmin">
<h3>Hey Admin!</h3>
<p>What would you like to do?</p>
</div>
<div *ngIf="!isAdmin">
<h3>Hey Regular User!</h3>
<p>What would you like to do?</p>
</div>
</ion-content>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment