Unable to connect to the cloud firestore backend specifically on the deployed version

When deploying the project using Vercel, I included my Firebase security and project details as environment variables on the Vercel dashboard. Authentication works fine during deployment, but there is an error in the console:

@firebase/firestore: Firestore (7.17.2): Unable to connect to Cloud Firestore backend. Connection failed 1 time. Latest error: FirebaseError: [code=invalid-argument]: Project id "my-project-id" is incorrectly formatted: it contains either invalid characters or is too long. Refer to this link for guidance on retrieving a project's id. This usually indicates that your device does not have a stable Internet connection at the moment. The client will function in offline mode until it can establish a successful connection to the backend.

The dependencies listed in package.json are:

  "dependencies": {
    "@material-ui/core": "^4.11.0",
    "@material-ui/icons": "^4.9.1",
    "firebase": "^7.15.5",
    "firebase-admin": "^8.12.1",
    "js-cookie": "2.2.1",
    "next": "latest",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-firebaseui": "4.1.0",
    "swr": "0.2.3"

I'm unsure which parts of my code are most relevant.. Here are snippets that work locally but encounter issues when deployed.

(handleSubmit with form)

const handleSubmit = (e) => {
    e.preventDefault();
    if (validate()) var user = firebase.auth().currentUser;
    var db = firebase.firestore();
    db.collection("users")
      .doc(user.uid)
      .collection("clients")
      .doc()
      .set({
        name: values.fullName,
        email: values.email,
        tel: values.mobile,
        postcode: values.postcode,
      })
      .then(function () {
        console.log("Document Succesfully Written");
      })
      .catch(function (error) {
        console.error("Error writing document: ", error);
      });
  };

(View list of client documents)

const Clients = () => {
  firebase.auth().onAuthStateChanged(function (user) {
    if (user) {
      const db = firebase.firestore();
      db.collection("users")
        .doc(user.uid)
        .collection("clients")
        .onSnapshot((snap) => {
          const clients = snap.docs.map((doc) => ({
            id: doc.id,
            ...doc.data(),
          }));
          setClients(clients);
        });
    } else {
      [];
    }
  });

  const [clients, setClients] = useState([]);

  return (
    <div>
      <ul>
        {clients.map((client) => (
          <li key={client.id}>{client.name}</li>
        ))}
      </ul>
    </div>
  );
};

export default Clients;

Answer №1

It's puzzling why this error occurred, but it seems like a simple solution fixed it. By deleting and replacing the environment variable in the Vercel dashboard without altering its contents, the issue was resolved upon redeployment. Now, the read/write operations are functioning correctly without any errors.

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

Firebase and React are having trouble communicating because it is unable to access the properties of 'auth'

The issue with the 'Cannot read properties of undefined (reading 'auth')' error in login.js may be related to where it is coming from. Login.js: import { useContext, useState, useEffect } from "react"; import { Link, useNavigate } f ...

Including JavaScript in HTML Error 404

https://i.stack.imgur.com/aQDPG.png I am struggling to understand why this import is not functioning as expected. I have tried using script/import.js but it still fails to work. The error message I keep receiving is: 127.0.0.1 - - [09/Sep/2020 15:09:35] ...

NextJS: encountered an error with fallback enabled

I have my NextJS setup on Vercel and here is how I configured getStaticPaths: const paths = posts.map((post) => ({ params: { player: post.player, id: post.id }, })) return { paths, fallback: true } However, when I set the fallback to true, I ...

Encountering the React.Children.only error while trying to use the <Link> component in Next.js

I'm encountering an issue with the code below: Error: React.Children.only expected to receive a single React element child. While trying to troubleshoot, I noticed that it only allows me to have one header under the link. <div className="co ...

Guide to dynamically loading customer data into an HTML table using JavaScript

I'm looking to populate a table with data on customers including their name, customer ID, and rental cost. Can anyone help me with the JavaScript code needed to insert this data into rows of the table? Your assistance is greatly appreciated. Below is ...

What is the best way to find the difference between two time moments using Moment

Hello everyone, I could really use some assistance with Moment.js. I have two input fields, one labeled Start and the other labeled Stop. start = moment().format('LT'); // This works when I click on the play button stop = moment().format(' ...

Verify login availability using Javascript auto-check

For quite some time now, I've been grappling with a significant issue that has been consuming my attention. I am determined to implement an auto-check login availability feature in the registration form of my website. My goal is for it to verify the ...

Strange response received from Stack Overflow API request

Having some issues with the code I'm using to call the Stack Overflow API: var request = require('request'); var url = 'http://api.stackexchange.com/2.2/search?order=desc&sort=activity&tagged=node.js&intitle=node.js&sit ...

What is the best way to transfer the http server variable between different layers in node.js without requiring it in a separate file?

I've developed a nodeJS application that involves creating a server in the file server.js. The code looks like this: http.createServer(app).listen(app.get('port'), function (err) { if (err) { console.error(err); } else { ...

Angular repeatedly executes the controller multiple times

I have been working on developing a chat web app that functions as a single page application. To achieve this, I have integrated Angular Router for routing purposes and socket-io for message transmission from client to server. The navigation between routes ...

NextJS 14 bug causing issues with getStaticPaths() and getStaticProps() for nested routes

Currently, I am in the process of setting up a blog structure that includes two levels of nested routes. You can access the posts at example.com/blogs/[chapterID]/[postID], and these static posts are saved as markdown files outside the app folder. https:/ ...

Exploring the Google Plus API: Discover individuals who are following a specific individual

Has anyone managed to successfully extract a list of individuals who have included a specific user in their circles or are following them on social media platforms? I am currently using the official JS Library for this task, but any solution in any progr ...

Enhance CKEditor with Linked Select Boxes Plugin

I have ventured into writing a CKEditor Plugin and have grasped the basic concepts. For instance: CKEDITOR.dialog.add( 'addDocumentGroupDialog', function ( editor ) { return { title: 'Link to a document group', min ...

Angular log out function to automatically close pop-up windows

Within my application, there is a page where users can open a popup window. When the user clicks on logout, it should close the popup window. To achieve this, I have used a static variable to store the popup window reference in the Global.ts class. public ...

Utilizing Selenium to inject javascript permanently or on every page refresh

In my selenium webdriver test using Python 3, I have implemented a semi-automated process. This means that some routines are automated while other tasks require user interaction with the browser, such as page refreshes or redirects. My challenge is to inj ...

Guide to running several versions of a single Next JS application with distinct configurations simultaneously on a shared server

My goal is to run 2 instances of the NextJS app on the same machine with different configurations and ports. The first instance runs on port 3000, while the second runs on port 3001, and this setup functions correctly with the commands: next dev next de ...

Obtain an item from an array by utilizing the property with Lodash _.find

I currently have an array of objects called memberToChange.checkboxes: ICheckbox[] structured like this: https://i.stack.imgur.com/LyKVv.png Within this setup, there is also a variable named internalNumber with the value "3419". My objective is to locate ...

Resource loading unsuccessful: server returned a 401 status code for React webpage

( ) I'm currently working on a website dedicated to searching for GitHub users as part of my React course. However, I seem to be facing an issue with the website not fetching the response properly, possibly due to an Axios error. When searching for ...

Is there a way to turn off autofocus in react-select?

Currently, I am using a selectbox from the "react-select" library. I am looking to implement a multi-select functionality without any wrapping as demonstrated in the sandbox provided. However, whenever I remove one of the chips or click on the input field, ...

There seems to be an issue with the pastebin api createPasteFromFile method as it is showing an error of 'create

I'm currently working on a logging system using node for a twitch chat. The idea is that when you type "!logs user" in the chat, it should upload the corresponding user.txt file to pastebin and provide a link to it in the chat. For this project, I am ...