Home > Net >  Firebase onValue doesn't fire and i don't know why
Firebase onValue doesn't fire and i don't know why

Time:08-03

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.

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

CodePudding user response:

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);
});

CodePudding user response:

You are right.

error handler

I have modified the rules and everything is workin now thanks !

  • Related