Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

490
Visualizações
Writing to Firebase database with node.js web server - "FIREBASE WARNING: set at ... failed: permission_denied"

I have a node.js web server, through which I am trying to write to Firebase. However, whenever it runs I get the following error message:

FIREBASE WARNING: set at /mydb failed: permission_denied 

Here is how I set up my application (relevant details):

var firebase = require('firebase');

var config = {
  apiKey: "8oc57xxx",
  authDomain: "example-04.firebaseapp.com",
  databaseURL: "https://example-ex04.firebaseio.com",
  projectId: "example-ex04",
  storageBucket: "example-ex04.appspot.com",
  messagingSenderId: "5022"
};

firebase.initializeApp(config);

function writeData(details) {
  firebase.database().ref('mydb/'). push({
    title: details.title,
    description: details.description,
    tags: details.tags
  }).then(function() {
    console.log('Upload succeeded');
  }).catch(function(error) {
    console.log('Upload failed');
  });;
}

Calling the function:

//what details looks like:
//{ title: 'Details',
  //description: 'Really fast, and awesome.',
  //tags: 'tag-1' 
//}

exports.postDetails = (req, res, next) => {
  writeData(req.body);

  const errors = req.validationErrors();

  if (errors) {
    req.flash('errors', errors);
    return res.redirect('/example');
  } 

  req.flash('success', { msg: 'Success!' });    
  res.redirect('/example');    
};

What do I need to do in order to get Firebase to accept my post? I have been reading over some docs on this:

https://firebase.google.com/docs/reference/js/firebase.database.Reference#set

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Have you finish your firebase sdk setting? You need to download a JSON file, and put it into your node server. Then initialize firebase with this code.

var admin = require("firebase-admin");

var serviceAccount = require("path/to/serviceAccountKey.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  apiKey: "8oc57xxx",
  authDomain: "example-04.firebaseapp.com",
  databaseURL: "https://example-ex04.firebaseio.com",
  projectId: "example-ex04",
  storageBucket: "example-ex04.appspot.com",
  messagingSenderId: "5022"
});

function writeData(details) {
  admin.database().ref('mydb/').push({
    title: details.title,
    description: details.description,
    tags: details.tags
  }).then(function() {
    console.log('Upload succeeded');
  }).catch(function(error) {
    console.log('Upload failed');
  });;
}

Calling the function:

//what details looks like:
//{ title: 'Details',
  //description: 'Really fast, and awesome.',
  //tags: 'tag-1' 
//}

exports.postDetails = (req, res, next) => {
  writeData(req.body);

  const errors = req.validationErrors();

  if (errors) {
    req.flash('errors', errors);
    return res.redirect('/example');
  } 

  req.flash('success', { msg: 'Success!' });    
  res.redirect('/example');    
};

You can check on this google site

Add the Firebase Admin SDK to your Server

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda