繁体   English   中英

无法连接到Firebase Realtime数据库NodeJS服务器

[英]Can't connect to Firebase Realtime Database NodeJS Server

当我尝试运行以下代码时,控制台中显示以下错误:

节点mcve.js防火墙警告:设置为/ sitesToVisit / -Kr6oOddLtLUcpUpha7m失败:Permission_denied(node:12540)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):错误:PERMISSION_DENIED:权限被拒绝

var firebase = require("firebase");
var config = {
    apiKey: "AIzaSyCJyakN_kwOnZ2f4-P0tzGdODEJeDsXt3w",
    authDomain: "seo-hero-fe0e8.firebaseapp.com",
    databaseURL: "https://seo-hero-fe0e8.firebaseio.com",
    projectId: "seo-hero-fe0e8",
    storageBucket: "seo-hero-fe0e8.appspot.com",
    messagingSenderId: "333356421370"
  };
  firebase.initializeApp(config);
    var database = firebase.database();
    var sitesToVisitRef = firebase.database().ref("sitesToVisit");
    var newSiteToVisitRef = sitesToVisitRef.push();
    newSiteToVisitRef.set({
      url: 'url',
      baseUrl: 'urlBase'
    });
var firebase = require("firebase");
var config = {
    apiKey: "apiKey",
    authDomain: "authDomain",
    databaseURL: "databaseURL",
    projectId: "projectId",
    storageBucket: "storageBucket",
    messagingSenderId: "messagingSenderId"
  };
  firebase.initializeApp(config);
    var database = firebase.database();
    var sitesToVisitRef = firebase.database().ref("sitesToVisit");
    var newSiteToVisitRef = sitesToVisitRef.push();
    newSiteToVisitRef.set({
      url: 'url',
      baseUrl: 'urlBase'
    });

更新:我尝试在新文件夹中创建一个新文件,该文件不在公共NPM软件包中。 这在我做一个简单的工作时起作用:

firebase.database().ref('usersecond').set({
    username: "ben",
    email: "hi",
    profile_picture : "imageUrl"
  });

初始化数据库后。 但是,当我添加其余代码时,该设置不会影响数据库。 它没有引发错误,但是数据没有显示在数据库中。 可能是因为我正在使用NPM请求模块吗?

看来您无权编写/sitesToVisit/-Kr6oOddLtLUcpUpha7m

如果此代码在受信任的环境 (例如您控制的设备/服务器或Cloud Functions)上运行,则考虑使用Firebase Admin SDK: https ://firebase.google.com/docs/admin/setup。 这将使代码以管理特权运行,而绕过安全规则。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM