【发布时间】:2019-08-16 10:59:22
【问题描述】:
我正在尝试使用 MST 操作在 firebase 中创建新用户。
我的代码如下所示:
.actions((self => ({
createUserWithEmailPassword:
flow(function*(password: string) {
console.log('creating user');
yield firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL);
console.log('set Persistence');
const user = yield firebase.auth().createUserWithEmailAndPassword(self.email, password);
console.log('CREATED USER', user);
self.uid = user.uid;
})
}));
它确实创建了一个用户,但它不会在createUserWithEmailAndPassword 调用之前进行。 (即它永远不会控制台“创建用户”)
我在用户上也有 onPatch 控制台,但它也不会显示用户更新。
我厌倦了安慰虚假的 api 调用
let res = yield fetch("https://randomapi.com/api/6de6abfedb24f889e0b5f675edc50deb?fmt=raw&sole")
这很好用。
createUserWithEmailAndPassword 似乎有问题,但我想不通。
【问题讨论】:
-
首先将
flow(function*(password: string) { })的内部封装到try ... catch中,以确保它不会引发错误。
标签: firebase react-native mobx mobx-state-tree