【发布时间】:2018-05-11 16:37:44
【问题描述】:
我正在使用 react-native redux 应用程序。这是我新创建的 firebase 数据库。
一切正常,用户也可以登录和注册。但是我在注册后有这个小代码我正在尝试.set({ firstname, lastname }) firstname, lastname,它没有反映在数据库中。 (github 仓库:https://github.com/steelx/react-native-redux-app)
export const signUpUser = ({ firstname = "", lastname = "", email, password }) => (dispatch) => {
dispatch({ type: SIGN_UP_REQUEST });
firebase.auth().createUserWithEmailAndPassword(email, password)
.then((user) => {
// const currentUser = firebase.auth().currentUser;
// currentUser.updateProfile({
// displayName: `${firstname} ${lastname}`,
// THIS WORKS
// })
firebase.database().ref('users/' + user.uid)
// THIS DOES NOT WORK
.set({ "firstname": 'AJINKYA', "lastname": 'AJINKYA' })
.then(() => {
dispatch({ type: SIGN_UP_SUCCESS, payload: user });
Actions.home();
});
})
.catch((error) => { dispatch({ type: SIGN_UP_FAILURE, payload: authFailMessage(error.code) }); });
};
Firebase 规则
{
"rules": {
"users": {
"$uid": {
".read": "auth != null",
".write": "auth != null && auth.uid == $uid"
}
}
}
}
【问题讨论】:
-
这里的
firstname和lastname是什么? -
“测试”、“测试”
String -
我发现我只能设置
displayName。这很好用 ==> firebase.auth().currentUser.updateProfile({displayName:${firstname} ${lastname}}) 但我的问题仍然存在,如果我想在数据库中添加条目怎么办。 -
酷。当您将这些值硬编码到
set时,您能否看到是否可以重现它,所以.set({ firstname: "test", lastname: "test" })。如果仍然重现它,我们可以排除变量的范围问题。 -
嗯...这可能是权限问题。您能否将
catch添加到set并记录任何错误。所以.set({ "firstname": 'AJINKYA', "lastname": 'AJINKYA' }).catch((error) => { console.error(error); }).then(...
标签: javascript firebase firebase-realtime-database firebase-authentication