首页 > 解决方案 > 如何将用户数据写入 Firebase 实时数据库?

问题描述

我不知道如何将用户输入的数据写入他在数据库中的特定文件夹中。

我想我应该从这样描述一个动作创建者开始:

export const updateUser = values => {
  const userId = AsyncStorage.getItem("userId");
  fetch(`https://sample-app.firebaseio.com/users/${userId}.json`,
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: {
     ...values
    }
  })
}

但我的数据库规则设置为:

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}

所以我不能将任何东西存储到数据库中

数据库

我究竟做错了什么?

标签: javascriptreactjsreact-native

解决方案


推荐阅读