skip to Main Content

firebase local emulation side:

initialize_app()

@https_fn.on_call( cors=options.CorsOptions(
        cors_origins="*",
        cors_methods=["get", "post", "options"],))
def validateEmail(req: https_fn.CallableRequest) -> Any :
    return {"text":{"valid:":"true"}}

The android app side.

    val func = Firebase.functions
    private fun validateEmail(str:String): Task<String> {
        val data = hashMapOf(
            "email" to str
        )
        return func.getHttpsCallable("validateEmail").call(data)
            .continueWith()
            {  task ->
                println("RAM_DBG" + task.result?.data.toString())
                task.result?.data as String

            }

    }

    override  fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        func.useEmulator("localhost", 5001)
        validateEmail("[email protected]")
            .addOnCompleteListener { task ->
                if (!task.isSuccessful)
                {
                    val e = task.exception
                    if(e is FirebaseFunctionsException)
                    {
                        println("RAM_DBG:" + e.code.toString() + e.details.toString())
                    }
                }
            }

This alwasy gives the FirebaseFunctionsException and code = INTERNAL. what is wrong?
What instrumentation and logging possibilites are there on both sides?
When running using curl like below

curl -H "Content-Type:application/json" -d @book.json -X POST http://127.0.0.1:5001/<app>/us-central1/validateEmail
{"result":{"text":{"valid":"true"}}}

Expecting the "valid:":"true" to be returned

2

Answers


  1. The key "valid:" might cause issues because of the colon. Change it to "valid"

    Login or Signup to reply.
  2. This isn’t right:

    func.useEmulator("localhost", 5001)
    

    In the Android emulator, "localhost" refers to the Android emulator virtual machine itself, which is not where your Firebase emulator is running. Your emulator is running on your development machine, which is referred to as 10.0.2.2 from within in the Android emulator. See the Android documentation for details:

    10.0.2.2 Special alias to your host loopback interface (127.0.0.1 on your development machine)

    See also the Firebase emulator documentation:

    // 10.0.2.2 is the special IP address to connect to the 'localhost' of
    // the host computer from an Android emulator.
    val firestore = Firebase.firestore
    firestore.useEmulator("10.0.2.2", 8080)
    

    See also:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search