简体   繁体   English

你应该在哪里初始化你的 firebase web 应用程序?

[英]Where are you supposed to initialize your firebase web app?

So I am brand new to web applications and I don't understand where I am supposed to initialize the my firebase app using this code:所以我是 web 应用程序的新手,我不明白应该在哪里使用以下代码初始化我的 firebase 应用程序:

        // Import the functions you need from the SDKs you need
    import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-app.js";
    import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-analytics.js";
  
    // Your web app's Firebase configuration
    const firebaseConfig = {
    // my firebase configuration would go here...
    };
  
    // Initialize Firebase
    const app = initializeApp(firebaseConfig);
    const analytics = getAnalytics(app);

Example:例子:

I will have 2 different pages for my web app (a login page and a home page).我的 web 应用程序将有 2 个不同的页面(登录页面和主页)。 I could initialize firebase in the login page and it would work fine for the first time the user logs into the website, but then what happens if the user returns to the website and they skip the login page and go straight to the home page because they are already logged in?我可以在登录页面中初始化 firebase 并且在用户第一次登录网站时它会正常工作,但是如果用户返回网站并且他们跳过登录页面和 go 直接进入主页会发生什么,因为他们已经登录? Does firebase not get initialized in this case because it never ran the login page code?在这种情况下,firebase 是否因为从未运行过登录页面代码而未被初始化? If so what am I supposed to do?如果是这样我该怎么办?

Once it loads a new page, the browser clears its memory of anything that happened on the previous page.加载新页面后,浏览器会清除其 memory 上一页发生的所有内容。 This means that you have to initialize Firebase every page that uses it.这意味着您必须初始化 Firebase 每个使用它的页面。

So if you use Firebase both on your login page and on your home page, you will have to initialize it on both of those pages.因此,如果您在登录页面和主页上都使用 Firebase,则必须在这两个页面上对其进行初始化。

暂无
暂无

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

相关问题 如何将 web 应用程序添加到您的 Google Cloud 控制台? - How do you add a web App to your Google Cloud console? ReactNative 在应用程序启动时初始化 Firebase? - ReactNative initialize Firebase at app start? “您试图通过调用 firebase.app() 来使用 Android 项目中未安装的 firebase 模块。” - "You attempted to use a firebase module that's not installed on your Android project by calling firebase.app()." 当我在 void main() 中初始化应用程序 firebase 时,它会为 web 抛出错误,但它与 android 一起工作正常 - When I initialize app firebase in void main() its throws an error for the web but its works fine with android 在何处生成 Firebase 数据库数据的 PDF - 移动应用程序或 Firebase 托管网络应用程序 - Where to generate a PDF of Firebase Database data - mobile app, or Firebase Hosting web app 错误默认的 Firebase 应用已经存在。 这意味着您多次调用 initialize_app() 而没有提供应用程序名称作为 - ERROR The default Firebase app already exists. This means you called initialize_app() more than once without providing an app name as the 如何在 firebase 管理员中初始化多个应用程序 - how to initialize multiple app in firebase admin Firebase Functions - 您已超出部署配额 - Firebase Functions - You have exceeded your deployment quota Serviceworker 必须是 web 应用程序清单中的字典 - Serviceworker must be a dictionary in your web app manifest 使用 Flutter 图标将 Firebase 添加到您的 Flutter 应用程序 - Adding Firebase to your Flutter app with Flutter Icon
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM