简体   繁体   English

Firebase onValue 没有触发,我不知道为什么

[英]Firebase onValue doesn't fire and i don't know why

I'm tryin to do a simple web3 app with Next/Js & Firebase.我正在尝试使用 Next/Js 和 Firebase 做一个简单的 web3 应用程序。

People can connect with their wallet from solana, to list their NFT, then choose one for connect in a game-container.人们可以从 solana 连接他们的钱包,列出他们的 NFT,然后在游戏容器中选择一个进行连接。

I'm stuck because i want to get infos from all connected players listed in Firebase.我被卡住了,因为我想从 Firebase 中列出的所有连接玩家那里获取信息。 then with the infos create some div in the game-container with all the connected players.然后使用信息在所有连接的玩家的游戏容器中创建一些 div。

But, when i try to get the snapshot of all the players, the onValue doesn't fire and i don't know why...但是,当我尝试获取所有玩家的快照时,onValue 没有触发,我不知道为什么......

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 !我已经修改了规则,现在一切正常,谢谢!

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

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