firebase多位置更新用户身份验证和数据库 [英] firebase multi-location updates user authentication and database

查看:84
本文介绍了firebase多位置更新用户身份验证和数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,可以使用电子邮件,密码,全名和电话号码来注册新用户.

I have a Form to signup new User with email, password, full name and phone number.

如果成功,我可以使用firebase.auth().createUserWithEmailAndPassword创建新用户.然后,我使用firebase.database().ref('users/..').set(..)将全名和电话号码保存到Firebase数据库中.

I can use firebase.auth().createUserWithEmailAndPassword to create new user if successfully. Then I use firebase.database().ref('users/..').set(..)to save fullname and phone number to firebase database.

但是,如果发生保存到数据库的处理错误(例如,通过规则write:false),我仍然在用户身份验证中创建了一个用户标识符.因此,存在一个没有电话号码和完整号码的用户.

But If the saving processing to database occur error (By rule write:false for example), I STILL have an user Identifier created in User Authentication. So an user exist without phone number and full number.

如何在多位置插入用户身份验证和数据库.如果这两个失败的Firebase之一自动拒绝插入新标识符并将其插入数据库. (只有两个都成功时,处理才会返回成功.)

How can I can multi-location insert user authentication and database. If one of these two failed firebase auto reject inserting new identifier and inserting into database. (The processing only return success if both success).

推荐答案

没有办法使Auth和Database组合操作成为原子操作.如果要成为原子用户,则应仅使用一项服务:数据库身份验证.

There is no way to make the combined Auth and Database operation atomic. If you want to be atomic, you should use only one service: the database or authentication.

要使其原子化,您可以将用户名,密码,全名和电话号码传递给Cloud Functions中的HTTP函数.然后使用电子邮件和密码创建用户,然后将全名和电话号码写入数据库.

To make this atomic you could pass username, password, full name, and phone number to a HTTP function in Cloud Functions. This then creates a user with the email and password, then writes the full name and phone number to the database.

但是请注意,这仍然不能保证是原子性的:您在电话上预期的故障可能会在服务器上发生.虽然机会要小得多,但无法保证.

But note that this still isn't guaranteed to be atomic: the same glitch that you're anticipating on the phone, could happen on the server. While chances are much smaller, there's no guarantee.

这意味着您需要确保代码足够健壮,以处理全名和电话号码丢失的情况.而且,如果您需要在服务器端执行此操作,那么如果您将跨产品代码留在客户端,它也将起到相同的作用.

This means you'll need to make sure that your code is robust enough to handle cases where the full name and phone number are missing. And if you need to do that in the server-side case, it will also work the same if you'd leave the cross-product code on the client.

这篇关于firebase多位置更新用户身份验证和数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆