Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firebase onValue doesn't fire and i don't know why

I’m tryin to do a simple web3 app with Next/Js & Firebase.

People can connect with their wallet from solana, to list their NFT, then choose one for connect in a game-container.

I’m stuck because i want to get infos from all connected players listed in Firebase. then with the infos create some div in the game-container with all the connected players.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But, when i try to get the snapshot of all the players, the onValue doesn’t fire and i don’t know why…

nothing happend, no console log or anything.

That’s my code and my database below

const database = getDatabase();
const reference = ref(database,'players/' + playerWallet);
const referenceDatabase = ref(database);

function initGame() {

  const allPlayersRef =  ref(database,'players/');


  onValue(allPlayersRef, (snapshot) => { // NEVEER HAPEND IDK  WHYYYYYYYYYYYYYYYY
    if (snapshot.exists()){
      console.log("Snap Exist");
    } else {
      console.log("snap is empty");
    }
    console.log("XXXXXXXXXXXXXXXXXXXXXXXXXX");
    //start every change occurs
    console.log("SNAP: "+snapshot.val());
    players = snapshot.val() || {};
    console.log("PLAYERS INFO : "+ players.playerName);

My database on Firebase

>Solution :

Are you sure the user has permission to read the data? If not, you’ll get an error message in the console of where the code executes. Alternatively, you can also detect such a permissions error with:

onValue(allPlayersRef, (snapshot) => {
  ...
}, (error) => {
  console.error(error);
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading