supabase/functions-js

Calling `invoke` via Android OS without specifying `content-type` header results in a failed request

MarcDerhammer opened this issue · 3 comments

Bug report

Describe the bug

If calling invoke using the example syntax from Android context, it results in a in a "Network Request Failed" from fetch. The actual error within fetch is { "isTrusted": false } (note: the request was https with valid certs)

I happened to be using supabase-js within a React-Native application and only encountered the problem on Android (not iOS)

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create an edge function
  2. Create an Android application using supabase-js
  3. Call supabase.functions.invoke(<functionname>, { body: JSON.stringify({foo: 'bar' })); (per the docs)
  4. Notice the error

Expected behavior

The request is sent properly

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]: Android 10
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: 1.33.3
  • Version of Node.js: 16.4.2

Additional context

Manually defining the "Content-Type": "application/json" header solves the problem. However, maybe the FunctionInvokeOptions could have a default value for Content-Type header. Or maybe the docs could hint at the issue. Just looking out for any future developer who may run into this same issue. If you think that's alright, let me know and I'd be happy to make a PR for either.

Thanks!

@MarcDerhammer I ran into this bug today.

Like you said, "Manually defining the "Content-Type": "application/json" header solves the problem."

Thank you so much!

vejja commented

+1
I would also love to have a FunctionInvokeOptions flag that indicates that the body is going to be a json object, and in that case:
1- add the "Content-Type": "application/json" header
2- automatically wraps the body object into JSON.stringify()
This would avoid a lot of boilerplate code for this usage

laktek commented

Closing this since this is fixed in newer releases.