user9722951
user9722951

Reputation:

What does this cloud function error mean?

I have this code to check whether an email is taken or not, it works it just throws back an error in the cloud functions logs, Here's the swift code:


 let functions = Functions.functions()
            functions.httpsCallable("uniqueEmail").call(email) { (result, error) in
                if let error = error as NSError? {
                    if error.domain == FunctionsErrorDomain {
                        let code = FunctionsErrorCode(rawValue: error.code)
                        let message = error.localizedDescription
                        let details = error.userInfo[FunctionsErrorDetailsKey]
                    }
                    // ...
                }
                if let text = (result?.data as? [String: Any])?["text"] as? String {
                    //self.resultField.text = text
                }
            }

Here's the cloud function code:


import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
admin.initializeApp()

exports.uniqueEmail = functions.https.onCall((req, res) => {
  const email = req.query.email;
  if (!email) {
    throw new functions.https.HttpsError('invalid-argument', 'Missing email parameter');
  }
  admin.auth().getUserByEmail(email)
  .then(function(userRecord) {
    // See the UserRecord reference doc for the contents of userRecord.
    console.log('Successfully fetched user data:', userRecord.toJSON());
    return({taken: true}); // Returns {"taken": "true"} or {"taken": "false"}
  })
  .catch(function(error) {
   console.log('Error fetching user data:', error);
   return({taken: false}); // Returns {"taken": "true"} or {"taken": "false"}
  });
});

And here's the error's I'm getting in cloud functions, I'm not sure what both mean, so could someone explain them both to me?

1.

Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions

2.


Unhandled error TypeError: Cannot read property 'email' of undefined
    at exports.uniqueEmail.functions.https.onCall (/user_code/lib/index.js:7:28)
    at /user_code/node_modules/firebase-functions/lib/providers/https.js:330:32
    at next (native)
    at /user_code/node_modules/firebase-functions/lib/providers/https.js:28:71
    at __awaiter (/user_code/node_modules/firebase-functions/lib/providers/https.js:24:12)
    at func (/user_code/node_modules/firebase-functions/lib/providers/https.js:294:32)
    at corsHandler (/user_code/node_modules/firebase-functions/lib/providers/https.js:350:44)
    at cors (/user_code/node_modules/firebase-functions/node_modules/cors/lib/index.js:188:7)
    at /user_code/node_modules/firebase-functions/node_modules/cors/lib/index.js:224:17
    at originCallback (/user_code/node_modules/firebase-functions/node_modules/cors/lib/index.js:214:15)

Upvotes: 0

Views: 696

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317758

The first message is just a warning and you can ignore it unless you're trying to make outbound connections.

The second message is saying that your function code is expecting to receive an input object with a property called "query" that's an object with a property called "email". But that's not what you're passing from the client. In the client, you passed a string (I assume, as you didn't say exactly what email is in your swift code).

Futhermore, I suspect that you might be confused about what callable functions take as arguments. You're showing (req, res) as arguments, a request and a response, which is what you would normally expect from a HTTP type function. But that's not how callables work. Now might be a good time to review the documentation for callable functions. The first argument to a callable function is the data object itself passed from the client. Use that instead, don't assume that the data is coming in through a query string.

Upvotes: 1

Related Questions