Skip to content

Handle CORS with cloud functions & reactfire functions SDK? #483

Answered by JurgenPalsma
JurgenPalsma asked this question in Q&A
Discussion options

You must be logged in to vote

Fixed my issue. For any newbies struggling on CORS like me, here is how I fixed it:

  1. Make sure your function is callable from other domains - set "allUsers/allAuthenticatedUsers" permissions to Invoke cloud function on your function

  2. Handle preflight options in your cloud function:
    if request.method == 'OPTIONS': headers = { 'Access-Control-Allow-Origin': '*', # <- Allow your function to be called from any domain 'Access-Control-Allow-Methods': 'POST', # <- POST or any method type you need to call 'Access-Control-Allow-Headers': 'Content-Type, Authorization', # <- Authorization Header needed 'Access-Control-Max-Age': '3600', } return ('', 204, headers)

  3. Allow Any origin after prefligh…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@kishore7403
Comment options

@manjunadha007
Comment options

Answer selected by JurgenPalsma
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants