1
我正在使用firebase雲功能在用戶註冊後將用戶添加到我的數據庫。 我想添加(例如創建用戶時)一個暱稱。 在註冊表格中,有一個暱稱框,但是如何將它發送給Firebase函數,以便將其添加到數據庫中的用戶?發送數據到firebase雲功能
這是火力功能:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const ref = admin.database().ref()
exports.createUserAccount = functions.auth.user().onCreate(event=>{
const uid = event.data.uid
const email = event.data.email
const photoUrl = event.data.photoUrl || 'https://vignette1.wikia.nocookie.net/paulblartmallcop/images/9/9c/Person-placeholder-male.jpg/revision/latest?cb=20120708210100'
const newUserRef = ref.child(`/users/${uid}`)
return newUserRef.set({
photoUrl: photoUrl,
email: email,
})
});
的登記表是在另一個文件(register.js),我怎麼可以從那裏將數據發送到功能?
我不叫createUserAccount任何地方,它被觸發時,此功能會發生:
handlePress = (navigation)=>{
if(this.state.password == this.state.verify){
firebaseRef.auth().createUserWithEmailAndPassword(this.state.email, this.state.password).then((newUser)=>{
const resetAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'Home'})
]
})
navigation.dispatch(resetAction)
}).catch(function(error){
console.log(error);
});
}else{
//password not match, show error.
}
}
提前感謝!
謝謝,我可以在我提供的代碼上有一個例子嗎?我是新來的,仍然掙扎 –
對於其他解決方案?我更新了我的答案 – Pipiks
謝謝! ....... –