尝试在 MST(mobx 状态树)操作中创建 firebase 用户
Trying to create firebase user in MST(mobx state tree)action
我正在尝试使用 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
调用之前进行。 (即它永远不会安慰 'CREATED USER`)
我在用户上也有 onPatch 控制台,但它也不会显示用户更新。
我厌倦了安慰假api电话
let res = yield fetch("https://randomapi.com/api/6de6abfedb24f889e0b5f675edc50deb?fmt=raw&sole")
这非常有效。
看起来 createUserWithEmailAndPassword
有问题,但我想不通。
您的代码应该可以工作,但您也可以试试这个
createUserWithEmailPassword(password: string) {
flow(function*() {
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;
})() // <--- check this
}
Flow 将return一个你需要调用的函数
或者像这样
createUserWithEmailPassword(password: string) {
const run = flow(function*() {
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;
})
run()
}
我正在尝试使用 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
调用之前进行。 (即它永远不会安慰 'CREATED USER`)
我在用户上也有 onPatch 控制台,但它也不会显示用户更新。
我厌倦了安慰假api电话
let res = yield fetch("https://randomapi.com/api/6de6abfedb24f889e0b5f675edc50deb?fmt=raw&sole")
这非常有效。
看起来 createUserWithEmailAndPassword
有问题,但我想不通。
您的代码应该可以工作,但您也可以试试这个
createUserWithEmailPassword(password: string) {
flow(function*() {
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;
})() // <--- check this
}
Flow 将return一个你需要调用的函数
或者像这样
createUserWithEmailPassword(password: string) {
const run = flow(function*() {
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;
})
run()
}