简体   繁体   English

将Ionic 2 Nativ Facebook与Firebase连接的最佳方法

[英]Best way to connect ionic 2 nativ facebook with firebase

at the moment iam implementing a signIn into my ionic 2 app. 目前,iam在我的ionic 2应用中实现了登录功能。

I want to use ionic 2 native facebook and somehow save the data to my firebase app. 我想使用ionic 2本机Facebook,并以某种方式将数据保存到我的Firebase应用程序。

Is there any way to archive that? 有什么办法可以存档吗?

One way is to create a new firebase auth user with the facebook email adress and some password hash, but maybe there is a better solution. 一种方法是使用Facebook电子邮件地址和一些密码哈希创建一个新的firebase auth用户,但是也许有更好的解决方案。

Here is what i got so far (i know, not much) :) 这是我到目前为止所得到的(我知道,不多):)

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);
    })
} }
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);
  });
}

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

我没有尝试过,所以可能无法100%正常工作,但是尝试一下我发现的Gist: https : //gist.github.com/katowulf/de9ef6b04552091864fb807092764224

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM