0

I am having trouble with some functions that have been working previously. I have created a function to let the user create another user and it was working fine. Functions that do not use Admin works fine just as before.

However, due to some Firebase updates, the function broke and I am getting an 'internal' error. I had to change import firebase from "firebase/app"; to import firebase from "firebase/compat/app"; as well as import "firebase/compat/functions"; but that did not work, as well as updating firebase to "^9.8.1", but that did not work either.

Here is my web function:

async registerUser(userInfo) {
    const functions = getFunctions();
    const createUser = httpsCallable(functions, "createUser");
      // Used to have this: 
      // let createUser = firebase.functions().httpsCallable("createUser");

    //Call to function where it breaks.
    return await createUser({
       //User data here
    })
      .then( 
    //stuff happens here
    ).catch((error) => {
      //Error happens here
})
}

Here is the function that was already deployed in Firebase:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();

  exports.createUser = functions.https.onCall(async (userData) => {
    return await admin
    .auth()
    .createUser(userData)
    .then(() => {
      return { isError: false };
    })
    .catch((error) => {
      return { isError: true, errorMessage: error };
    });
});

Here is the response log:

Request Method: OPTIONS
Status Code: 403 
Referrer Policy: strict-origin-when-cross-origin
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
content-length: 305
content-type: text/html; charset=UTF-8
date: Tue, 24 May 2022 16:04:14 GMT
server: Google Frontend
Leminur
  • 291
  • 2
  • 7
  • 22
  • HTTP `403` means that authentication has failed. – Martin Zeitler May 24 '22 at 16:39
  • But what authentication? I can access the database just fine, as well as any CRUD operations that don't use `firebase admin`. It was working just fine a month before. – Leminur May 24 '22 at 16:45
  • Literally `403` is "Forbidden"; possibly executing admin operations with user authentication - or the security rules may interfere. – Martin Zeitler May 24 '22 at 16:49
  • Were there any recent updates that could prevented the system from working? It was working just fine a couple of months ago and I did not change anything at all. Also, is there any way to log this error besides 'internal'? I have granted overall permission and I still had the same error. – Leminur May 24 '22 at 21:01
  • My exp with Firebase is that CORS error messages are usually not CORS related... Firebase functions console logs are usually more helpful. – Jonathan Aug 18 '22 at 12:55

1 Answers1

1

You can refer to the Admin SDK error handling page and check the Structure of the error, the refer to policy: strict-origin-when-cross-origin part gives us a good starting point.

But first, we can see the root cause of this issue as in the same page we have a table for Platform error codes where:

INTERNAL | Internal server error. Typically a server bug.

In the Firebase Admin Authentication API Errors we have a similar table where:

auth/internal-error | The Authentication server encountered an unexpected error while trying to process the request. The error message should contain the response from the Authentication server containing additional information. If the error persists, please report the problem to our Bug Report support channel.

Now talking about the cors message, this question suggests:

Consider importing like this, as shown in the samples:

const cors = require('cors')({origin: true});

And the general form of your function will be like this:

 exports.fn = functions.https.onRequest((req, res) => {
   cors(req, res, () => {
       // your function body here - use the provided req and res from cors
   })
});

You might need to make some changes to the structure as the question has some time, so I will also leave the reference to the Call functions via HTTP requests and check if it works for you.

I will follow up if you provide updates and consider submitting a bug report as previously mentioned by the documentation if this is necessary.

Alex
  • 778
  • 1
  • 15
  • Hey Alex! Thanks for your huge help! I have tried to use CORS as requested, but it does not work at all. I have been using `onCall` instead of `onRequest` as you wrote up there. However, the only error that I can log is 'FirebaseError: internal'and that is it. I have tried using `functions.logger.log("Login Create Client");` in my Function but I could not log anything at all because it seems like it does not even execute that function. It seems that the error happens in `registerUser`, in the catch I put there. What do you think it might be? – Leminur May 30 '22 at 20:33