Guest User

Untitled

a guest
Nov 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <ion-card *ngIf="userProfile">
  2. <img [src]="userProfile.photoURL"/>
  3. <ion-card-content>
  4. <ion-card-title>
  5. {{ userProfile.displayName }}
  6. </ion-card-title>
  7. <p>
  8. The UID for this new user is {{userProfile.uid}} and the email is
  9. {{userProfile.email}}
  10. </p>
  11. </ion-card-content>
  12. </ion-card>
  13.  
  14. userProfile: any;
  15.  
  16. constructor(public navCtrl: NavController, public navParams: NavParams, public _authProvider: AuthProvider) {
  17. }
  18.  
  19. _fbLogin() {
  20. this._authProvider._fbLogin();
  21. }
  22.  
  23. _signOut() {
  24. this._authProvider._signOut();
  25. }
  26.  
  27. userProfile: any = null;
  28. constructor(public _afAuth: AngularFireAuth, public _fb: Facebook) {
  29. console.log('Hello AuthProvider Provider');
  30. }
  31.  
  32. _fbLogin(){
  33. this._fb.login(['email']).then( (response) => {
  34. const facebookCredential = firebase.auth.FacebookAuthProvider
  35. .credential(response.authResponse.accessToken);
  36.  
  37. firebase.auth().signInWithCredential(facebookCredential)
  38. .then((success) => {
  39. console.log("Firebase success: " + JSON.stringify(success));
  40. this.userProfile = success;
  41. })
  42. .catch((error) => {
  43. console.log("Firebase failure: " + JSON.stringify(error));
  44. });
  45.  
  46. }).catch((error) => { console.log(error) });
  47. }
  48.  
  49. _signOut(){
  50. this._afAuth.auth.signOut();
  51. }
  52.  
  53. _afAuth.authState.subscribe((user: firebase.User) => {
  54. if (!user) {
  55. this.userProfile = null;
  56. return;
  57. }
  58. this.userProfile = user.displayName;
  59. });
Add Comment
Please, Sign In to add comment