[英]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.