【发布时间】:2019-06-04 21:09:03
【问题描述】:
我正在尝试使用 redux 商店更改我的 firebase 用户名。
我有一个注册表单,它接收输入的电子邮件、密码和用户名,然后表单使用电子邮件和密码创建一个 firebase 帐户,然后我使用 firebase 的 updateProfile 更新 displayName。看到这个
那是我的 redux reducer:
case "CHANGE_USERNAME":
const currentUser = firebase.auth().currentUser;
currentUser.updateProfile({ displayName: state.user.displayName });
return { ...state.user, displayName: action.payload };
这是商店:
const initialState = {
logged: null,
user: {}
};
这是我的注册表的一部分:
firebase
.auth()
.createUserWithEmailAndPassword(this.state.email, this.state.password)
.then(() => {
this.props.dispatch({
type: "CHANGE_USERNAME",
payload: { ...this.state.username }
});
alert("Account created!");
})
.catch(error => {
// Handling errors
var errorCode = error.code;
var errorMessage = error.message;
alert(errorCode);
});
为什么用户名没有改变?
【问题讨论】:
-
这些警报
alert("Account created!");alert(errorCode);是否有效?如果不是这个函数createUserWithEmailAndPassword不返回Promise -
是的,我收到了 Account created!,不好的是承诺不会改变我的 Redux 存储
标签: javascript reactjs firebase redux firebase-authentication