通过电子邮件限制Firebase用户 [英] Restrict Firebase users by email

查看:79
本文介绍了通过电子邮件限制Firebase用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户希望能够列出可以访问数据的受限制电子邮件.因此,其他任何进入该应用程序的人都根本无法读取/写入任何数据(理想情况下甚至无法登录,但我认为Firebase无法实现此功能?).关于如何解决这个问题的任何想法?我曾想过要有一系列接受的电子邮件,并检查它们的电子邮件是否存在于安全规则中,但这似乎不起作用.我的数据库中有以下内容:

I have a client that would like to be able to make a list of restricted emails that can access the data. So anyone else coming to the app can't read/write any data at all ( ideally can't even log in but I don't think that's possible with Firebase? ). Any ideas on how to go about this? I had thought of having an array of accepted emails and checking whether their email existed in the security rules but that didn't seem to work. I had the following in the database:

"validEmails": ["test@test.com"]

,然后在安全规则中:

".read": "root.child('validEmails').val().indexOf(auth.token.email) > -1"

但是您似乎不能在这些安全规则中使用indexOf.

But it looks like you can't use indexOf in those security rules.

也许我需要有一个可接受的电子邮件列表,然后当用户进行注册时,检查它们是否在该列表中并将其UID添加到接受列表中?我想我可以通过云功能或其他方式来做到这一点?

Maybe I need to have a list of acceptable emails, and then when a user signs up it checks whether they're in that list and adds their UID to an accepted list? I guess I could do this through a cloud function or something?

任何帮助将不胜感激.

欢呼

推荐答案

谢谢大家,我最终要做的是列出可接受的电子邮件列表:

Thanks guys, what I ended up doing was having a list of acceptable emails:

{
    "validEmails": ["test@test.com"],
    "validUsers": {}
}

,然后运行云功能以检查用户何时注册了他们的电子邮件是否在有效的电子邮件列表中.如果是,则将其添加到有效用户列表中;如果不是,则删除新创建的用户.我还设置了数据规则,以便只有validUsers内的用户才能访问数据.

and then have a cloud function run to check when a user signed up if their email was in the valid email list. If it was then it added them to the valid users list and if not it deleted the newly created user. I also set up data rules so that only users within validUsers could access the data.

然后,前端处理了无效用户的重定向等.

The front-end then handled the redirection etc for invalid users.

这篇关于通过电子邮件限制Firebase用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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