【问题标题】:Firebase - Get user id of the user who just performed an operation on the databaseFirebase - 获取刚刚对数据库执行操作的用户的用户 ID
【发布时间】:2017-06-14 04:20:32
【问题描述】:

将项目推送到 Firebase 中的某个列表后,我想使用 update 在新创建的项目上添加 createdBy 属性。这个属性应该是登录用户的UID,但是我不确定如何在我第一次登录时不存储它来获取它。

如果不做上述事情,是否有可能以某种方式得到它?

请注意,我不想要event 的密钥

这就是我想要的:

let ref = this.af.database.list('/events');

ref.push(eventCopy).then((event) => {

  const uuid: string = theUserWhoJustPushed.uuid;

  ref.update(event.key(), {createdBy: uuid});
});

【问题讨论】:

  • Firebase 身份验证用户有一个 UID,而不是 UUID。您可能需要更新您的词汇表以防止混淆。除此之外,您是否尝试过firebase.auth().currentUser.uid? (见firebase.google.com/docs/auth/web/…
  • @FrankvanPuffelen 我可以发誓他们像 1-2 年前一样将其更改为 UUID?还是他们从 UUID 改变了?反正我会试试的。
  • 值的格式已更改(已更改多次)。但是该属性(并且一直是)称为用户 ID 并缩写为 UID。

标签: angular firebase firebase-authentication angularfire2


【解决方案1】:

我认为如果您创建服务来做到这一点会更好。在此服务的构造函数中,您将通过订阅 firebase 身份验证来获取用户。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    • 2018-05-14
    • 1970-01-01
    • 2017-09-04
    • 1970-01-01
    • 2011-07-28
    • 2014-08-23
    相关资源
    最近更新 更多