Vue-Firebase: A guide to linking multiple Firebase services in a single app

I am facing an issue with connecting to two firebases within the same project.

In my project, I have two javascript files that connect to each firebase separately, which seems fine.

Here is how I import them:

  import db from '../FireBase'
  import mdb from '../MissionFireBase'

  let MissionRef = mdb.ref('mission');
  let TeamRef = db.ref('Teams');
  let StartRef = db.ref('start');

Each firebase (db and mdb) works individually, but when I try to use both of them together, I encounter an error:

index.cjs.js?3b8b:360 Uncaught FirebaseError {code: "app/duplicate-app", message: "Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).", name: "[DEFAULT]", stack: "[DEFAULT]: Firebase: Firebase App named '[DEFAULT]…0)↵    at fn (http://localhost:8080/app.js:89:20)"}

It appears that there is a conflict because somewhere along the line, Firebase gets assigned a default ID. Even when I call each one from a different Vue component, the same error persists.

This is how the firebase connection is established:

import Firebases from 'firebase'

let config = {

  apiKey: "--",
  authDomain: "--",
  databaseURL: "--",
  projectId: "--",
  storageBucket: "--",
  messagingSenderId: "--"

};

let apps= Firebases.initializeApp(config);
let mdb = apps.database();

export default mdb

My question is, is it possible to make two different firebase calls in this scenario, or do I need to merge them into a single connection?

Thank you.

Answer №1

Achieving this is entirely feasible. You will need to establish distinct FirebaseApp instances for each, and then access your database from there.

var additionalAppConfig = {
    apiKey: "<ANOTHER_API_KEY>",
    authDomain: "<ANOTHER_PROJECT_ID>.firebaseapp.com",
    databaseURL: "https://<ANOTHER_DATABASE_NAME>.firebaseio.com",
    storageBucket: "<ANOTHER_BUCKET>.appspot.com",
};
// Initialize a new app with a different configuration
var another = firebase.initializeApp(additionalAppConfig, "additional");

// Retrieve the database.
var additionalDatabase = another.database();

To delve deeper into this topic, refer to the section utilizing multiple projects in your application within the Firebase documentation.

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

Adding a JSON file to an Angular app hosted on a Grunt server

I'm currently following a beginner's guide for Angular and I need to incorporate a JSON file into my project. I started off by using Yeoman to set up my application, which is running on grunt. var phonecatApp = angular.module('phonecatApp& ...

Code for remotely connecting to a server and starting a Node.js application called app.js via SSH

I am attempting to establish an SSH connection to two servers sequentially in order to execute the following command: sudo node app.js This is the code I am using: #!/bin/bash while read line; do ssh -i "sshtest.pem" ec2-user@$line "sudo node app. ...

sending parameters into a regex within a function

Struggling to pass a variable into a robust regex, managing to make it work outside the function but unable to figure out how to get it working within a function. Not sure why match[1] is returning null or how to find words after a keyword. Here's wh ...

Using jQuery to dynamically insert variables into CSS styles

I am attempting to use jQuery 3 to modify the CSS of a class and change the background color. My first step is converting an rgba color code (properties.color) to a hexadecimal code, which is functioning correctly. Next, I try to change the background co ...

Creating a seamless thread using AngularJS

I am working on a Spring MVC application that utilizes HTML and Angular on the client side. I have a method in my Angular controller that needs to run every 5 seconds. How can I achieve this using Angular? Thank you for your assistance. $scope.inspectio ...

Load the dropdown menu in the select element using the AngularJS $ngresource promise

I have a select box on my webpage that I need to fill with data received from a server. I am currently using a service to fetch this data, but I'm unsure how to access the values returned from the promise and populate the ng-options in the select tag. ...

Having trouble setting a value as a variable? It seems like the selection process is not functioning properly

My Hangman game has different topics such as cities and animals. When a user selects a topic, the outcome should be a random item from that specific topic. For example: London for cities or Zebra for animals. Currently, I am only generating a random lett ...

Is it advisable to use type="text/plain" for JavaScript?

I recently came across instructions on how to implement a particular feature out of curiosity. I found it interesting but was puzzled when they mentioned that in order for it to function properly, certain steps needed to be followed: You must identify any ...

The `Route` component is expecting a `function` for the `component` prop, but instead it received an `object`

For a while now, I've been grappling with an issue that seems to be unique to me. The problem lies within my component and container setup for the start screen rendering at the initial route. components/DifficultySelection.jsx import React from &apo ...

Any number of elements in a single JSX code snippet

In my React code, I've created a function called optionTemplate to be used as a prop in a React component. const optionTemplate = (option) => { return ( <div className="flex align-items-center gap-2" style={ ...

Creating links within a single image in HTML?

Is there a way to hyperlink different parts of a single image to various webpages using JavaScript coordinates or any other method? ...

The functionality of sending a response to a client in Node.js Express seems to be malfunctioning

I am facing an issue with sending a response back to the client. Despite not receiving any errors, it seems like the response is not working as expected. Can anyone help me figure out why? Below is my code snippet: exports.login = function (req, res, next ...

Eliminating event listeners in Nuxt/Vue application

In my current project on Nuxtjs 2.13, I have a question regarding the removal of event listeners. Is it necessary and how should I go about doing it? I'm not referring to traditional JavaScript methods like addEventListener and removeEventListener. I ...

What steps can be taken to resolve the error ERROR TypeError: undefined is not an object when evaluating 'userData.username'?

.I need help fixing this error ERROR TypeError: undefined is not an object (evaluating 'userData.username') Currently, I am working on a small application where users are required to allow permission for their location in order to save their cit ...

Guide on how to automatically direct users to a page upon successful login in ReactJS

How can I redirect to the homepage after a successful login in ReactJS? Also, how can I display an error message when a user enters incorrect credentials? I have attempted the following code, but it does not successfully redirect to the homepage or show ...

Using Three.js and EffectComposer to create interactive masking with an UnrealBloomPass

Struggling with dynamically masking an UnrealBloomPass using the EffectComposer and encountering unexpected outcomes. Uncertain if missing a crucial concept or exploring the wrong approach. Any insights would be greatly valued. The composer consists of th ...

Encountering a "Parsing error: Unexpected token, expected ";" " when developing a React application with the provided code

I am currently working on developing a React application, and I have encountered an issue in my app.js file regarding the render function. Despite being new to JavaScript, I am unable to figure out why this error is occurring. Apologies if it is due to a s ...

What steps should I take to create a slider using my image gallery?

I have a unique photo gallery setup that I'm struggling with: As I keep adding photos, the cards in my gallery get smaller and smaller! What I really want is to show only 4 photos at a time and hide the rest, creating a sliding effect. I attempted ad ...

Creating an Angular project that functions as a library and integrating it into a JavaScript project: a step-by-step guide

Is it feasible to create an Angular library and integrate it into a JavaScript project in a similar manner as depicted in the image below? The project structure shows trading-vue.min.js being used as an Angular library. Can this be done this way or is th ...

Firebase is displaying an error when using onSnapshot, specifically when a value is being waited on from an

Currently, I am working on an application where I am categorizing posts and users based on a specific room ID. I am adding a roomid property to both the user and every post. However, when attempting to fetch all posts belonging to a particular room ID, I e ...