Home > Software engineering >  Google Firebase httpsCallable raising net::ERR_NAME_NOT_RESOLVED
Google Firebase httpsCallable raising net::ERR_NAME_NOT_RESOLVED

Time:12-28

I am running into net::ERR_NAME_NOT_RESOLVED when calling the API of my firebase project. I have tried using multiple devices, two internet connections, a VPN, Linux, macOS, Windows 11 to rule out any errors caused by my devices. When navigating to the API link on my browser it does not timeout, and I am provided with a response. The issue seems to be when using the httpsCallable function provided by Firebase. No logs of the function being called are present on firebase outside of navigating to it in a browser.

Here is my code:

const functions = firebase.functions
console.log(functions)
const loginWithCode = httpsCallable(functions, 'loginWithCode')

loginWithCode(loginPayload)
    .then((result) => {
        console.log(result)
    })
    .catch((error) => {
        console.log("ERROR CAUGHT HERE")
        console.log(error)
    });

The output from my browser console:

service.ts:206 POST https://us-central1-"crowd-pleaser-75fd7",.cloudfunctions.net/loginWithCode net::ERR_NAME_NOT_RESOLVED
App.tsx:79 ERROR CAUGHT HERE
App.tsx:80 FirebaseError: internal

The result from directly inputting the link on the firebase web interface:

{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}

Is there something I am missing that is creating this issue? I have scoured the internet, and StackOverflow looking for an answer, and all solutions provided have not worked. The method implemented is exactly how it is done on the Firebase docs here

Edit: It seems like the link to which my post request is being sent is formatted oddly. Maybe this could be the issue? I can't figure out why it's formatted this way though.

CodePudding user response:

I found a solution to the problem. My speculation in my edit was correct, the URL to which the post request was being sent by httpsCallable was formatted incorrectly. I am unsure as to why it was being formatted this way, however, the quick solution is to set the customDomain class attribute of the object returned by getFunctions to the correct domain. In my case this was done by doing:

functions.customDomain = functions.customDomain = 'https://us-central1-crowd-pleaser-75fd7.cloudfunctions.net'

The variable 'functions' in the code above is the class attribute returned from the method getFunctions provided by Firebase

CodePudding user response:

The Thing

While I'm not an expert on Firebase the problem is that you're making a wrong HTTP request with loginWithCode(loginPayload), there is nothing wrong with your code that I can see at least.

By the way, you're using: const loginWithCode = httpsCallable(functions, 'loginWithCode') rather than a simple const loginWithCode = httpsCallable('addMessage') as described here: Google FireBase Docs

And then, making a loginWithCode({ text: messageText })

Also, as you can see here: Google Firebase Docs:firebase.functions.HttpsCallable

You will be able to pass any type of data to the HttpsCallable function, so we end at the start point: you're making a wrong HTTP request.

As described in the HTTP answer the error is: net::ERR_NAME_NOT_RESOLVED this happens when a DNS request cannot be resolved, then a domain doesn't exists so this all leads to the thing that there is no way to send the HTTP request since there is not a route in the internet that was found to send it.

The Problem:

While decoding the url that you're making the HTTP request

service.ts:206 POST https://us-central1-"crowd-pleaser-75fd7",.cloudfunctions.net/loginWithCode net::ERR_NAME_NOT_RESOLVED
App.tsx:79 ERROR CAUGHT HERE
App.tsx:80 FirebaseError: internal

You will find that you're sending the HTTP request to:

https://us-central1-"crowd-pleaser-75fd7",.cloudfunctions.net/loginWithCode

As you can see, you will find that when making the HTTP request it will be a problem: since you cannot put "crowd-pleaser-75fd7", in the URL to make the HTTP request. That is generating the error net::ERR_NAME_NOT_RESOLVED

I'm not sure what exactly are you trying to do, but I think that the correct URL to the HTTP request should be:

https://us-central1-crowd-pleaser-75fd7.cloudfunctions.net/loginWithCode

With this URL the HTTP request must pass, at least. And I suggest then check the loginPayload in order to fix this.

  • Related