简体   繁体   中英

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.

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

我在 Firebase 上的数据库

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

You are right.

error handler

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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