简体   繁体   English

从Firebase到我的博客中获取数据库数据而无需身份验证

[英]Fetch database data from firebase to my blog without auth

I've followed the guide from a documentation of firebase on how to fetch the data. 我遵循了Firebase文档中的指南,了解如何获取数据。

I try to play around with the: sample of firebase here 我尝试玩一下: Firebase示例在这里

However, to get database data need to auth. 但是,要获取数据库数据需要进行身份验证。 Is there anyway just only fetch like feed from firebase without auth? 无论如何,是否只有从Firebase像feed那样获取内容而没有auth? I need to read on my own blog to be read for public. 我需要在自己的博客上阅读才能公开阅读。

Please..help me to solve this issue. 请..帮助我解决这个问题。

Thanks. 谢谢。

You could set your rules to this: 您可以为此设置规则:

{
  "rules": {
    ".read": "true",
    ".write": "auth != null"
  }
}

But this means anyone who has access the database can read all the data. 但这意味着任何有权访问数据库的人都可以读取所有数据。

In your code you would do something like this: 在您的代码中,您将执行以下操作:

firebase.database().ref("blogItems").on('value', function(snapshot) {
    console.log(snapshot.val());
});

If your setup is like this: 如果您的设置是这样的:

firebase-database-123
  |
  |_blogItems
      |
      |_entry1
      |
      |_entry2

I would recommend you get familiar with Firebase Database Security Rules . 我建议您熟悉Firebase数据库安全规则 These are the ones which dictate who can read/write into the Firebase Database. 这些决定了谁可以读写Firebase数据库。

All new projects starts with the rules 所有新项目都从规则开始

{
 rules: {
  .read: auth != null,
  .write: auth != null
 }
}

This means anyone who isn't authenticated won't be able to read or write in our database. 这意味着未经身份验证的任何人将无法在我们的数据库中进行读取或写入。

To achieve what you might need without compromising other data you may do something like the following: 为了实现您可能需要的功能而不损害其他数据,您可以执行以下操作:

{
 rules: {
  .read: auth != null,
  .write: auth != null

  blogEntries: {
   .read: true,
   .write: auth != null
  }
 }
}

By doing this you are allowing everyone to read the data inside blogEntries, and this means ALL the data inside, while if someone wants to write data to blogEntries they should be authenticated. 通过这样做,您允许所有人读取blogEntries中的数据,这意味着其中的所有数据,而如果有人想将数据写入blogEntries,则应该对其进行身份验证。

I recommend watching The key to Firebase Security to further understand what can be achieved and how Security Rules work. 我建议观看Firebase Security的钥匙,以进一步了解可以实现的内容以及安全规则的工作方式。

Yes, you can get the data without authenticating, but it's not recommended . 是的,您无需验证即可获取数据,但不建议这样做 I did the following setup in the Firebase. 我在Firebase中进行了以下设置。 Step 1 第1步 第1步

Click on Realtime Database's GET STARTED 单击实时数据库的入门

Step 2 第2步 第2步

Click on second option start in test mode you can access data without auth 单击第二个选项以测试模式启动,您可以不经过身份验证即可访问数据

or Add following lines in rules 或在规则中添加以下行

{
  "rules": {
  ".read": true,
  ".write": true
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 web 上的身份验证规则从 Firebase 实时数据库中读取数据? - How to read data from Firebase Realtime Database with the auth rule on web? 如何在 React JS 中从 firebase 实时数据库中获取数据 - How fetch data from firebase realtime database in react js 如何在 React js 中从 firebase 实时数据库中获取数据 - how to fetch data from firebase realtime database in react js 如何从 Firebase 获取数据到我的 React 应用程序中 - How can I fetch data from Firebase into my React App firebase-auth 中的哪个 firebase 值在我自己的数据库中用作 uid? - Which firebase value from firebase-auth to use as uid in my own database? 无法显示React中的Axios获取方法响应,无法在我的博客应用程序中以数组的形式从Firebase获取数据 - Axios get method response in React cannot be displayed getting data from firebase as an array in my blog application 如何使用 firebase 云函数从 firebase-realtime-database 中获取数据? - How to fetch data from firebase-realtime-database using firebase cloud functions? 如何使用云函数从我的 Firebase 实时数据库中 database.ref 正在侦听的节点内部获取数据? - How can I fetch data from inside a node which the database.ref is listening to in my Firebase real-time database using cloud functions? 如何在云功能中获取firebase数据库数据? - How to fetch firebase database data in cloud function? 我的while无法正常从数据库中获取php中的数据 - My while does not work properly to fetch the data in php from database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM