Ionic2 + AngularFire2 + Facebook Auth

Hi Guys!,

I have started an Ionic 2 project with Angularfire 2 following this tutorial:
https://playcode.org/getting-started-with-angular-2-typescript-and-firebase-angularfire2/

The login is working, but after login I want to get the user email, display name, profile image url and access token.

I don’t know how to do it and the events property is private:

import { Component, OnInit } from '@angular/core';
import { AngularFire, FirebaseListObservable } from 'angularfire2';
import { Routes, Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router';

import { AboutComponent } from './+about';
import { HelpComponent } from './help';


@Component({
  moduleId: module.id,
  selector: 'example-app',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  directives: [ROUTER_DIRECTIVES],
  providers: [ROUTER_PROVIDERS ]
})
@Routes([
  {path: '/about', component: AboutComponent},
  {path: '/help', component: HelpComponent}
])
export class ExampleAppComponent implements OnInit {

  title = 'It works!';

  constructor(private af: AngularFire, private router: Router) {

  	this.af.auth.subscribe(auth => {
  		
      console.log(af.auth);

      // Get user email, etc. How?

  	});
  }

  login() {
    this.af.auth.login();
  }
}

Any help?

OK, I’ve found it:

console.log(af.auth.getAuth().facebook.accessToken);

Thank you!!

I followed the article you posted but it does not have anything related to the login, to my question, should I install Cordova Facebook plugin? or I can use Firebase auth simply without any cordova plugins?

No, you don’t need the plugin.

Please, check this:
https://firebase.google.com/docs/auth/web/facebook-login
(Advanced: Handle the sign-in flow manually)

Good luck!

@Corin you are incorrect… you need a plugin or a javascript library to handle the facebook login to get the access_token for this to work with Ionic2

@m_abdelfattah

here is an example: https://github.com/aaronksaunders/basicaf2

1 Like