简体   繁体   中英

Best way to connect ionic 2 nativ facebook with firebase

at the moment iam implementing a signIn into my ionic 2 app.

I want to use ionic 2 native facebook and somehow save the data to my firebase app.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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