Having the Firebase functionality up and running smoothly, but encountering issues with the firebase.auth() method

After running npm i firebase and importing firebase from 'firebase/compat/app', I encountered an error when trying to use firebase.auth(). The error message states that no Firebase App '[DEFAULT]' has been created, even though I have followed the setup documentation provided by Firebase.

console.log(firebase) displays correct data in the console, indicating that firebase is set up properly. However, the issue arises when attempting to use firebase.auth() in Vue3.

I am currently stuck at this step while trying to get firebaseUI to work. Once firebase.auth() works correctly, I can initialize the firebaseUI widget using the following code:

var ui = new firebaseui.auth.AuthUI(firebase.auth());

My firebase configuration file (./src/firebaseConfig.js) includes the necessary initialization of firebaseApp using initializeApp() method. This configuration is then imported and used in my component file (./src/components/HelloWorld.vue):

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <div id="sign-in-status"></div>
    <div id="sign-in"></div>
    <pre id="account-details"></pre>
  </div>
</template>

<script>
import firebaseConfig from '../firebaseConfig';

import firebase from 'firebase/compat/app';
import * as firebaseui from 'firebaseui'
import 'firebaseui/dist/firebaseui.css'

console.log(firebaseConfig);
console.log(firebase);

// Initialize the FirebaseUI Widget using Firebase.
var ui = new firebaseui.auth.AuthUI(firebase.auth());

export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>

While logging firebaseConfig and firebase works without any issues, initializing the FirebaseUI Widget produces the previously mentioned error. I am still working on finding a solution to resolve this problem.

Answer №1

After encountering the same issue, I discovered some key points that helped me understand why some users were unaffected while others experienced bugs.

  1. It is crucial to initialize the app before using firebaseUI. This can be done in various ways such as main.js, importing configuration.js, or ensuring initialization before authentication.

  2. The initialization of firebaseApp (from your firebaseConfig.js) differs from importing firebase from 'firebase/compat/app'.

  3. If firebaseUI is called before proper initialization or when not initialized at all, errors may occur. It is important to consider the Vue lifecycle in such cases.

To ensure proper initialization, make sure to import firebaseApp and not just firebaseConfig into HellowWorld.vue.

In my scenario, the 'new firebaseUI' is implemented in the mounted() method of ChildView. I initialize firebaseApp in main.ts, eliminating the need for further initialization in ChildView - it only requires importing firebase from 'firebase/compat/app'.

If you require assistance with code examples, feel free to reach out and I can provide insights based on my experience.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for integrating @mdx-js/loader with your create-react-app project

Following the guidelines found at: The steps I took were: $ npx create-react-app react-app $ cd react-app $ npm install @mdx-js/loader Then, according to the instructions, I created the src/content.mdx file like this: # Hello, world! This is **markdown* ...

Is JavaScript Gallery Acting Up? Possible Layer Glitch!

Seeking assistance with a website issue. I have an index.php file set up with a sideshow script in the head that appears on all pages. Additionally, within the index.php file, there is a portfolio.html page that displays a gallery script when loaded. The p ...

What is the best way to allow all authenticated routes to display the Devise ajax Login form?

I have successfully incorporated Devise to accept Ajax Login and have designed a form for logging in via ajax, displayed within a modal. However, I am only able to view the form and login when I set up event binders for specific buttons that activate the m ...

Tips for arranging the items within the slider according to the specified direction (rtl, ltr) in the Owl Carousel slider for Angular

Is there a way to dynamically change the direction of the owl-carousel-o angular slider based on the selected language? Currently, I have set rtl: true in the owl-carousel configuration during initialization. However, when the user switches to a different ...

List of Keys in MongoDB: The Ultimate Guide to Retrieving Object Keys

{ "_id": "1", "style": "13123", "category": "dress", "colors": { "Black": { "prestock": 50, "instock": 60, "inactive": 0 }, "Blue": { "prestock": 30, "instock": 0, "inactive": 0 }, ...

Unraveling the intricacies of a website template downloaded alongside a webpack ES6 project

My colleague in the office was adamant about purchasing a stunning HTML/CSS/JS external template to serve as a foundational design for our website project. This particular website is a significant endeavor that we are constructing using Laravel, SASS, and ...

Navigating through webdriverjs elements until a specific text value is found is a useful technique in test

Can anyone help me understand how looping in WebDriverJs works with promises? Imagine you have the following html structure: <div id="textelements"> <span onclick="spanClicked('Rock')">Rock</span> <span onclick="s ...

What is the best way to generate an array of objects by extracting specific properties from another array object?

Here is the information provided: const cocktail = [ { "idDrink":"13070", "strDrink":"Fahrenheit 5000", "strGlass":"Shot glass", "strInstructions":&qu ...

Exploring the method of accessing one Vue plugin from another plugin with the use of Vue.prototype

I'm currently working on developing a Vue plugin aimed at simplifying the management of authentication state throughout my application. This particular plugin will require interaction with other Vue plugins such as vuex, vue-router, and vue-apollo (fo ...

What is the best way to incorporate modal window parameters into this code snippet?

JavaScript function: function loadBlockEditor(block, username) { var blockInfo = $.ajax({ url: "in/GameElement/BlockEditor.php", type: "GET", data: 'block=' + block + '&nick=' + username, dataType: "html" }); b ...

Encountered an error while trying to create module kendo.directives using JSPM

I am attempting to integrate Kendo UI with Angular in order to utilize its pre-built UI widget directives. After running the command jspm install kendo-ui, I have successfully installed the package. In one of my files, I am importing jQuery, Angular, and ...

Adding a border to the <area> element: A step-by-step guide

Can a border be added around an <area> element? This would be useful for testing an imagemap, however the following code does not achieve the desired effect: area { outline: 1px solid red; border: 1px solid red; } ...

Having trouble triggering the button with querySelector in Angular

I have a dynamic page where I need to click on a button. I tried the code below, but it is not working and not showing any alert. However, if we use the same code in the browser console, it executes and shows an alert. Can someone please suggest how to r ...

Show the text based on the current count of the counter

Currently, I have a simple Javascript counter function: <body> <script type="text/javascript"> var clicks = 0; function onClick() { clicks += 1; document.getElementById("clicks").innerHTML = clicks; }; </ ...

What is the process to manually trigger hot reload in Flutter?

I am currently developing a Node.js application to make changes to Flutter code by inserting lines of code into it. My goal is to view these updates in real-time. Is there a way to implement hot reload so that every time I finish writing a line in the file ...

Utilizing array iteration to display images

I am having trouble getting the images to display on my card component. The description appears fine, but the images are not rendering properly even though I have the image data in an array. Here is the Card Component code: export const Card = (props) =&g ...

JavaScript: Share module contents internally through exporting

When working with Java, there are 4 different visibility levels to consider. In addition to the commonly known public and private levels, there is also the protected level and what is referred to as the "default" or "package-local" level. Modifier Clas ...

Variability in Swagger parameter declaration

Is it possible to specify input parameters in Swagger with multiple types? For example: Consider an API that addresses resources using the URL http://localhost/tasks/{taskId}. However, each task contains both an integer ID and a string UUID. I would like ...

Exploring the wonders of nested object destructuring in ES6

How have you been? I want to remove the property "isCorrect" from a nested object. Original List id: 1, questionText: 'This is a test question for tests', answerOptions: [ { answerText: 'A', isCorrect: ...

Supporting multiple types for matching object structures is a feature in Jest

I'm currently working on a test using jest to verify if an object key is either a string or a number. It seems like a basic task, but surprisingly there isn't much guidance in the documentation. Test Example: test('Checking asset structure ...