亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

創建用戶身份驗證后,我無法將數據保存到數據庫

創建用戶身份驗證后,我無法將數據保存到數據庫

收到一只叮咚 2022-09-02 17:23:23
在firebase上創建用戶身份驗證后,我無法將數據保存到數據庫中,控制臺上出現以下錯誤:“TypeError:firebase.auth (...)。當前用戶為空”。創建身份驗證后,代碼似乎無法讀取用戶的 uid代碼:createUserButton.addEventListener('click', function(){firebase.auth().createUserWithEmailAndPassword(emailInput.value, passwordInput.value)    var user = {        nome: "Pedro",        sobrenome: "Ribeiro",        cpf: "946.201.340-31",        uid: firebase.auth().currentUser.uid,        email: emailInput.value,        password: passwordInput.value    }    writeUserData(user).catch(function(error) {// Handle Errors here.     })})function writeUserData(user) {    firebase.database().ref('users/' + firebase.auth().currentUser.uid).set(user).catch(error =>{    console.log(error.message)  })}需要更改哪些內容,以便代碼可以讀取用戶的 uid 并將數據保存在數據庫中?
查看完整描述

1 回答

?
婷婷同學_

TA貢獻1844條經驗 獲得超8個贊

您不會等到新用戶創建過程完成后再寫入數據庫。createUserWithEmailAndPassword 返回一個承諾,該承諾在工作完成后解析。它將為您提供一個要使用的 UserCredential 對象。

firebase.auth().createUserWithEmailAndPassword(emailInput.value, passwordInput.value)

.then(userCredential => {

    // write the database here

})

.catch(error => {

    // there was an error creating the user

})


查看完整回答
反對 回復 2022-09-02
  • 1 回答
  • 0 關注
  • 121 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號