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

查看:28
本文介绍了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()都会为我​​返回该用户.我应该在这里存储用户信息(年龄,体重等),还是应该在我的数据库中创建一个 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/电子邮件仍然保持不变,因此可以仍然链接到他们的旧数据.

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天全站免登陆