Home > Software design >  Where are you supposed to initialize your firebase web app?
Where are you supposed to initialize your firebase web app?

Time:02-14

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:

        // 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). 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? Does firebase not get initialized in this case because it never ran the login page code? If so what am I supposed to do?

CodePudding user response:

Once it loads a new page, the browser clears its memory of anything that happened on the previous page. This means that you have to initialize Firebase every page that uses it.

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.

  • Related