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

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

问题描述

我正在开发一个带有 firebase、angular 和 angularfire 的应用程序.我想实施一个邀请协作者"功能与 Firebase 本身实现协作的方式大致相同——也就是说,应用程序用户可以输入电子邮件地址来邀请协作者,协作者将发送电子邮件并生成inviteToken",就像邀请协作者进入一样火力基地本身.我知道安全规则(限制合作者访问)和架构设计(一个/collaborators 'folder' ?)是一方面,可以使用本机 firebase 和 angular 来完成.我的问题是如何最好地实施邀请电子邮件和inviteToken"?实现这种邀请功能的最方便的方法是什么?可以使用本机 Firebase 完成吗?或者是否需要实现单独的服务器端代码(nodejs?)?也许 firebase 团队的某个人可以根据 firebase 本身如何实现协作来发表意见.

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.

>

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

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)" 
      }
    }
  }
}

现在,当user1"想要与user2"共享item1"时,他们只需写入值user2"并在权限键下将其设置为true.您可以将权限"键的结构扩展为您想要的粒度(例如:协作者只能读取,但所有者可以读取和写入等)

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.)

在实践中,例如,您可能希望使用用户电子邮件地址的哈希值.另请查看简单登录,了解一种对您的用户进行身份验证的简便方法(一旦通过身份验证,上述安全规则中使用的 auth 变量将自动为您设置).

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