2016-07-25 50 views
3

Firebase v3 Auth提供updateProfile方法,將displayNamephotoURL傳遞給Firebase。Firebase v3 updateProfile方法

我的理解是,這些屬性是從第三方oAuth提供商Google,Facebook,Twitter或GitHub在用戶登錄後檢索的。在基於密碼的身份驗證的情況下,它們不可用或可從管理控制檯查看。

我可以存儲密碼身份驗證帳戶的此信息,如果可以,我可以通過管理控制檯查看/管理此信息?

順便說一句:我知道這可以存儲在實時數據庫下的users節點/分支,但我問的是將這些信息存儲在Firebase身份驗證系統中。

enter image description here

// Updates the user attributes: 
user.updateProfile({ 
    displayName: "Jane Q. User", 
    photoURL: "https://example.com/jane-q-user/profile.jpg" 
}).then(function() { 
    // Profile updated successfully! 
    // "Jane Q. User" 
    var displayName = user.displayName; 
    // "https://example.com/jane-q-user/profile.jpg" 
    var photoURL = user.photoURL; 
}, function(error) { 
    // An error happened. 
}); 

// Passing a null value will delete the current attribute's value, but not 
// passing a property won't change the current attribute's value: 
// Let's say we're using the same user than before, after the update. 
user.updateProfile({photoURL: null}).then(function() { 
    // Profile updated successfully! 
    // "Jane Q. User", hasn't changed. 
    var displayName = user.displayName; 
    // Now, this is null. 
    var photoURL = user.photoURL; 
}, function(error) { 
    // An error happened. 
}); 

回答

3

.updateProfile存儲在火力地堡驗證系統的displayNamephotoURL性質。因此,您不需要在實時數據庫的users節點下設置/獲取這些內容。

您不會在Firebase v3 Auth控制檯中看到這些屬性。這是不可見的。

集於一身,在這裏如何註冊用戶,口令:

registerPasswordUser(email,displayName,password,photoURL){ 
    var user = null; 
    //nullify empty arguments 
    for (var i = 0; i < arguments.length; i++) { 
    arguments[i] = arguments[i] ? arguments[i] : null; 
    } 

    firebase.auth().createUserWithEmailAndPassword(email, password) 
    .then(function() { 
    user = firebase.auth().currentUser; 
    user.sendEmailVerification(); 
    }) 
    .then(function() { 
    user.updateProfile({ 
     displayName: displayName, 
     photoURL: photoURL 
    }); 
    }) 
    .catch(function(error) { 
    console.log(error.message); 
    }); 
    console.log('Validation link was sent to ' + email + '.'); 
}