将 ionic 2 nativ facebook 与 firebase 连接的最佳方式

Best way to connect ionic 2 nativ facebook with firebase

目前我正在对我的 ionic 2 应用程序实施登录。

我想使用 ionic 2 native facebook 并以某种方式将数据保存到我的 firebase 应用程序。

有什么方法可以存档吗?

一种方法是使用 facebook 电子邮件地址和一些密码哈希创建一个新的 firebase 身份验证用户,但也许有更好的解决方案。

这是我到目前为止得到的(我知道,不多):)

import {NavController, Loading, Platform, Storage, LocalStorage} from "ionic-angular";
import {OnInit, Inject, Component} from "@angular/core";

import {ForgotPasswordPage} from "../forgot-password/forgot-password";
import {SignUpPage} from "../sign-up/sign-up";
import {HomePage} from "../../home/home";
import * as firebase from 'firebase';
import {Facebook} from 'ionic-native';

/*
 Generated class for the LoginPage page.

 See http://ionicframework.com/docs/v2/components/#navigation for more info on
 Ionic pages and navigation.
 */
@Component({
    templateUrl: 'build/pages/auth/login/login.html',
})
export class LoginPage {
    private local: any;

    constructor(private navCtrl: NavController, private platform:Platform) {
        this.local = new Storage(LocalStorage);
    }



openForgotPasswordPage():void {
     this.navCtrl.push(ForgotPasswordPage);
}

openSignUpPage():void {
    this.navCtrl.push(SignUpPage);
}

login() {
    firebase.auth().signInWithEmailAndPassword("test@test.com", "correcthorsebatterystaple").then(function (result) {
        console.log("AUTH OK "+ result);
    }, function (error) {
        console.log("dawdaw");
    });
}

facebookLogin() {
    Facebook.login(['public_profile', 'user_birthday']).then(() => {
        this.local.set('logged', true);
        this.navCtrl.setRoot(HomePage);
    }, (...args) => {
        console.log(args);
    })
} }

我没试过这个,所以可能不是 100% 有效,但试试这个我发现的要点:https://gist.github.com/katowulf/de9ef6b04552091864fb807092764224

facebookLogin() {
  Facebook.login(['public_profile', 'user_birthday']).then((result) => {
    var creds = firebase.auth.FacebookAuthProvider.credential(result.access_token);
    return firebase.auth().signInWithCredential(creds);
  })
  .then((_user) => {
    console.log("_user:", _user);
  })
  .catch((_error) => {
    console.error("Error:", _error);
  });
}

在此处查看更多信息 - https://firebase.google.com/docs/auth/web/facebook-login#advanced-handle-the-sign-in-flow-manually