简体   繁体   English

在Ionic + Firebase中使用ngCordovaOauth处理Facebook / Google登录

[英]Handling Facebook/Google login with ngCordovaOauth in Ionic + Firebase

I'm trying to implement Firebase authentication with angularfire signInWithCredential method for my Ionic app. 我正在尝试使用Ionic应用程序的angularfire signInWithCredential方法实现Firebase身份验证。 As I'm using Firebase 3.x SDK, the methods signInWithRedirect and signInWithPopup are not yet supported on mobile devices. 当我使用Firebase 3.x SDK时,移动设备尚不支持signInWithRedirect和signInWithPopup方法。 Thus I'm using the plugin ngCordovaOauth. 因此,我正在使用插件ngCordovaOauth。

var ref = firebase.database().ref().child("users");
$scope.users = $firebaseArray(ref);
$cordovaOauth.facebook("//removed_client_id", [ "public_profile", "email"]).then(function(result) {
  var credentials = firebase.auth.FacebookAuthProvider.credential(result.access_token);
  $scope.authObj.$signInWithCredential(credentials).then(function(authData) {
    var existUser = $scope.users.$getRecord(authData.uid);
    if(existUser == null){
      $scope.user = {
        uid: authData.uid,
        displayName: authData.displayName,
        avatar: authData.photoURL,
        email: authData.email,
        contact: "0000000000",
        provider: "facebook"
      }
      firebase.database().ref("users/" + authData.uid).set($scope.user);
    }
    $rootScope.result = authData;
    $state.go("menu.home");
  }, function(error) {
    console.error("ERROR: " + error);
  });
}, function(error) {
  console.log("ERROR: " + error);
});

The problem that I'm facing is I have no idea what the structure of 'authdata' is as I couldn't find any documentation for the same. 我面临的问题是我不知道'authdata'的结构是什么,因为我找不到相同的任何文档。 With sigInWithPopup, firebase returns 'result' object; 使用sigInWithPopup,firebase返回“结果”对象; contents of which can be accessed like 'result.user.uid', 'result.user.displayName' or 'result.user.email'. 可以访问诸如“ result.user.uid”,“ result.user.displayName”或“ result.user.email”之类的内容。 How can I achieve the same here as I'm trying to store the user profile when he logs in for the first time? 我要在首次登录时尝试存储用户个人资料,如何在此实现相同的目的? Any help? 有什么帮助吗? I'm testing on android device. 我正在android设备上进行测试。 Thank you! 谢谢!

signInWithCredential returns a promise that resolves with a firebase.User same as signInWithEmailAndPassword and all other sign in apis. signInWithCredential返回一个使用firebase解析的promise.user与signInWithEmailAndPassword和所有其他登录api相同。 Check the docs for more info on firebase.User: https://firebase.google.com/docs/reference/js/firebase.User 检查文档以获取有关Firebase的更多信息。用户: https//firebase.google.com/docs/reference/js/firebase.User

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

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