Firebase:我应该将用户数据存储在身份验证配置文件还是数据库中 [英] Firebase: should I store user data on the authentication profile or database

查看:19
本文介绍了Firebase:我应该将用户数据存储在身份验证配置文件还是数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 FirebaseAuth.instance.verifyPhoneNumber() 在我的 Flutter 应用中注册了一个用户.这非常有效,用户会显示在我的 Firebase 控制台中.

I signed up a user in my Flutter app using FirebaseAuth.instance.verifyPhoneNumber(). This works perfectly and the user shows up in my Firebase Console.

FirebaseAuth.instance.currentUser() 现在每当我打开应用程序时都会为我返回用户.我应该在此处存储用户信息(年龄、体重等),还是应该在我的 Database 中创建一个 users 集合并链接 currentUser().uid 在那里?

FirebaseAuth.instance.currentUser() now returns the user for me whenever I open the app. Should I store user info (age, weight etc.) here, or should I create a users collection in my Database and link the currentUser().uid in there?

此外,我应该将其存储在与 uid 链接的数据库中,还是与登录信息链接的数据库中.例如,将 user 链接到 phoneNumber 而不是 uid.因为如果你删除了用户,但他们又想重新注册,那么他们会得到一个新的uid,但他们的phoneNumber/email 仍然保持不变,因此可以仍然链接到他们的旧数据.

Also, should I store it on the Database linked against the uid, or linked against the login info. For example, link a user to the phoneNumber and not the uid. Because if you ever delete the user, but they want to register again, then they will get a new uid, but their phoneNumber / email will still stay the same and can therefore still link to their old data.

推荐答案

您不能向 Firebase 身份验证用户配置文件添加任意数据.所以你应该将额外的数据存储在一个数据库中,并且确实将它与用户的 UID 相关联,以便你可以轻松地查找它.这也让您可以更轻松地实现用户搜索,因为客户端 Firebase 身份验证 SDK 没有任何功能可以查找除当前登录用户之外的任何用户的数据.

You can't add arbitrary data to the Firebase Authentication user profile. So you should store the additional data in a database, and indeed associate it with the UID of the user, so that you can easily look it up. This also allows you to implement searches for users more easily, as the client-side Firebase Authentication SDKs have no functionality to look up data for any user but the currently signed in one.

另外一个问题:如果用户从您的应用程序中删除了他们的帐户,您应该尊重他们的意愿并删除您为他们存储的其他数据.

To the additional question: if a user deletes their account from your application, you should respect their wishes and delete the additional data that you store for them too.

这篇关于Firebase:我应该将用户数据存储在身份验证配置文件还是数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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