首页 > 解决方案 > 如何安全地访问 firebase 数据以自动填充网页?

问题描述

当用户进入事件页面时,我希望 JS 自动从 FIREBASE 检索数据并填充 HTML(无需用户登录)。我在发布的代码中使用了“signInAnonymously”函数。它似乎有效,但我如何也自动注销???我想要做的甚至可能吗?我尝试在各个地方使用 firebase.auth().signOut() 无济于事。

    (function () {
  // Initialize Firebase
  var config = {
    apiKey: "xxxx",
    authDomain: "xxxx.firebaseapp.com",
    databaseURL: "https://xxxxx.firebaseio.com",
    projectId: "xxxxxxx",
    storageBucket: "xxxxxxx.appspot.com",
    messagingSenderId: "xxxxxxxxxxx"
  };

  firebase.initializeApp(config);

  firebase.auth().signInAnonymously();

  let database = firebase.database();
  let ref = database.ref('events');

  // Query DB - init UI once
  ref.once('value', getDBData, DBerror);


  // Data parsing and DOM manipulation code follows here but no issues with that part........



}());

标签: javascriptfirebasefirebase-authentication

解决方案


推荐阅读