2014-10-20 24 views
0

得到user.uid隨着火力地堡1.0.21和$ firebaseSimpleLogin - 註冊用戶 - 我做了這樣的事情:升級到1.1火力地堡:不能從的createUser()

app.controller('AuthCtrl', function ($scope, $firebase, $firebaseSimpleLogin) { 
    var ref = new Firebase(MY_FIREBASE_URL); 
    var auth = $firebaseSimpleLogin(ref); 

    $scope.register = function (valid) { 
    // user contains email ad password fields, from my view 
    auth.$createUser($scope.user.email, $scope.user.password).then(function (auth) { 
     // auth.user.uid is defined, here; for example: 'simplelogin:13' 
     // ... 
    }); 
    }; 
}; 

隨着火力地堡1.1, $ firebaseSimpleLogin已被棄用,並且它的功能集成在Firebase核心中。
所以我 - 信任我:-) - 改變了這樣的代碼:

app.controller('AuthCtrl', function ($scope, $firebase) { 
    var ref = new Firebase(MY_FIREBASE_URL); 
    var auth = $firebase(ref); 

    $scope.register = function (valid) { 
    // user contains email ad password fields, from my view 
    auth.$createUser($scope.user.email, $scope.user.password).then(function (auth) { 
     // ... 
    }); 
    };  
}; 

雖然,我得到$的createUser()爲 '未定義' ...
所以我也嘗試:

app.controller('AuthCtrl', function ($scope, $firebase) { 
    var ref = new Firebase(MY_FIREBASE_URL); 
    var auth = $firebase(ref); 

    $scope.register = function (valid) { 
    // user contains email ad password fields, from my view 
    ref.createUser({ 
     email: $scope.user.email, 
     password: $scope.user.password 
    }, function(err) { 
     if (!err) { 
     // ??? how do I access uid from here ??? 
     } 
    }); 
    };  
}; 

我確實希望ref.createUser()應該返回一個promise,比如auth。$ createUser做的,但事實並非如此。
所以,我不知道熱讓我的新鮮用戶的UID,將其插入到我的用戶擴展信息的對象數組...

+0

這是怎麼回事的問題(或答案來)從以前的一個不同:HTTP://計算器。 com/questions/26390027/firebase-authwithoauthredirect-woes? – 2014-10-20 20:04:09

+0

弗蘭克,這是非常不同的...與前一個我問如何使用*認證*方法('authWithOAuthRedirect')沒有成功的回調('onAuth()'是答案)。現在我問如何使用'createUser'功能...有沒有'onUserCreated()'方法? :-) – MarcoS 2014-10-21 07:27:04

+0

好的,這是新用戶註冊時的情況嗎?我應該已經意識到,基於'$ scope.register'。 :-) – 2014-10-21 10:59:13

回答

1

AngularFire取決於「火力點」:「1.0.x系列」和「firebase-簡單登錄「:」1.6.x「,因此,Firebase核心上的身份驗證方法尚未在AngularFire中實現。

你有兩個選擇:

不升級火力地堡,並繼續使用與AngularFire的版本1.0.x和火力地堡簡單登錄

或者,升級火力地堡到1.1但你必須刪除AngularFire和火力地堡簡單登錄並僅使用Firebase方法。由於您使用的是AngularJS,因此您可能需要使用$ q服務將Firebase方法封裝到帶有promise的函數中,並且您需要使用$ scope。$ apply在某些情況下是因爲取決於您在做什麼Angular不知道$範圍有變化,並沒有觸發這些變化。

$應用API參考:https://docs.angularjs.org/api/ng/type/ $ rootScope.Scope

火力地堡1.1 API參考:https://www.firebase.com/docs/web/api/

+0

我明白了。下一版本的AngularFire會完全支持Firebase 1.1嗎?如果會的話,我肯定會等待它... – MarcoS 2014-10-26 08:04:38

+0

我認爲他們正在努力,我們必須等待...... – 2014-10-26 16:11:58