如何使用Firebase实施协作者邀请? [英] How to implement collaborator invitations using firebase?

查看:182
本文介绍了如何使用Firebase实施协作者邀请?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序与firebase和angularfire和angularfire。我想要实现
邀请协作者功能,就像firebase本身实现协作的方式一样 - 也就是说,应用用户可以输入电子邮件地址邀请协作者发送电子邮件并生成inviteToken ,就像在邀请Firebase本身的合作者时一样。
我了解安全规则(限制协作者访问)和模式设计(a /协作者文件夹?)是一个方面,可以使用本地的Firebase和角色来完成。我的问题是如何最好地实现邀请电子邮件和inviteToken?什么是实施这种邀请功能最方便的方式?可以使用本地的Firebase完成吗?或者需要实现单独的服务器端代码(nodejs?)?也许firebase团队的成员可以根据firebase本身如何实现协作来进行选择。

解决方案

您可以通过散列用户的电子邮件地址来实现协作,它在一个权限字段下。



例如,让我们从user1拥有的路径/ items / item1开始:

  {
items:{
item1:{
data: foobar,
permissions:{
user1:true
}
}
}
}

$ b

您将为数据设置安全规则,如下所示:

<$ p $ {
rules:{
items:{
$ item:{
.read:data.child ('permissions')。hasChild(auth.uid),
.write:data.child('permissions')。hasChild(auth.uid)
}
}






现在当'user1'想分享'item1'与'用户2',他们将简单地写入值'user2',并在权限键下将其设置为true。您可以扩展'权限'键的结构,使其尽可能精细(例如:协作者只能读取,但拥有者可以读取和写入等)。

<例如,实际上,您可能想要使用用户电子邮件地址的哈希值。此外,还要看看简单登录(Simple Login),以便您对用户进行身份验证(一旦通过身份验证,就会自动为您设置上述安全规则中使用的 auth 变量) p>

I am developing an app with firebase and angular and angularfire. I would like to implement a "invite collaborators" feature in much the same way as firebase itself implements collaboration - that is, the app user can enter an email address to invite collaborators which would send an email and generate an "inviteToken", just as is done when inviting collaborators in firebase itself. I understand that security rules (to limit collaborator access) and schema design( a /collaborators 'folder' ? ) are one aspect, which can be accomplished using native firebase and angular. My question is how to best implement the invite email and the 'inviteToken'? What would be the most expedient way to implement such an invitation feature? Could it be done using native firebase? Or would one need to implement separate, server side code (nodejs?)? Perhaps someone from the firebase team can opine based on how firebase itself implements collaboration.

解决方案

You can implementation collaboration by hashing the email address of the user you want to share a particular piece of data with, and storing it under a permissions field.

For example, let's start with a path /items/item1 that is owned by 'user1':

{
  "items": {
    "item1": {
      "data": "foobar",
      "permissions": {
        "user1": true
      }
    }
  }
}

You'd set the security rules for the data as follows:

{
  "rules": {
    "items": {
      "$item": {
        ".read": "data.child('permissions').hasChild(auth.uid)",
        ".write": "data.child('permissions').hasChild(auth.uid)" 
      }
    }
  }
}

Now when 'user1' wants to share 'item1' with 'user2', they will simply write the value 'user2' and set it to true under the permissions key. You can extend the structure of the 'permissions' key to be as granular as you want (eg: collaborators can only read, but owner can both read and write, etc.)

In practice, you may want to use hashes of the user's email addresses, for example. Also take a look at Simple Login for an easy way to authenticate your users (once authenticated, the auth variable used in the security rules above are automatically set for you).

这篇关于如何使用Firebase实施协作者邀请?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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