【问题标题】:VueJS + Firebase: Matching Keys Between Authenticated User And Users CollectionVueJS + Firebase:经过身份验证的用户和用户集合之间的匹配键
【发布时间】:2017-11-01 18:58:42
【问题描述】:

VueJS 中,我想创建一个名为 users

Firebase 数据库集合

此集合应存储有关身份验证的每个用户的信息。

我希望每个经过身份验证的用户的id 成为此集合中的id

我该如何解决这个问题?

【问题讨论】:

    标签: firebase firebase-realtime-database vue.js


    【解决方案1】:

    目前,我将uid 属性从通过调用您选择的身份验证方法解决的对象中提取出来,在我的情况下,它是createUserWithEmailAndPassword,然后使用uid 作为参考在数据库上设置它。我还将我目前对用户的了解添加到该对象中,例如 OAuth 为您提供的任何内容,或者您​​的表单提供的任何内容。

    ESNext 中的一个示例,在异步函数中,以及电子邮件/密码验证:

    const {uid} = await firebase.auth().createUserWithEmailAndPassword(email, password)
    
    firebase.database().ref(`users/${uid}`).set({
      email,
    })
    

    他们下次登录时,您可以使用他们的 uid 提取他们的用户数据。

    至少,这就是我正在做的事情。我也是 Firebase 的新手。

    【讨论】:

      猜你喜欢
      • 2020-02-22
      • 1970-01-01
      • 2018-08-18
      • 2020-11-15
      • 2016-01-17
      • 1970-01-01
      • 2017-09-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多