Firebase Upload with Firebase Auth

Hi @appgyver team , how does the Firebase Upload flow function know if an user is authorised? The reason I’m asking is, I replaced all my Firebase auth related flow functions with HTTP Requests (to make it work better with Firestore rules). My firebase uploads stop working when I set the storage rules to allow only auth users to write new files. It works fine when the storage is made public. Is there a workaround to make the Firebase Upload work with Firebase auth?

You have to include an authentication header for the user. Is there a specific reason why you use HTTP request instead of the ready-made functions that would do this for you automatically?

1 Like

@Kaushik_Bhattacharya : you can find every step in detail and with screenshots here Firestore; security rules : if request.auth != null; - #21 by stayfoolish . Look out for the 'Bearer '+idToken
@Mevi : the ready-made functions do not support sub-collections in Firebase. For me that was the reason to switch all functions to ‘HTTP request’. Or was there an update in the meantime since August '21, which I missed?

1 Like

I switched to the http request instead of the readymade firebase auth components (email authentication, current user, persistence) as I was not being able to extract the fresh Id tokens from currently signed user. I’m using this Id token for the Authorization header in my data sources. This is working fine so far as Firestone collections are concerned. But couldn’t figure out how to do the same with file upload. Please guide me if I’m doing anything wrong.

How can I extract the Id token after sign-in and Get current user flow components?

Another information I missed - I used rest API connection for connecting to Firestone collections

@stayfoolish ohh I see, that makes sense. Thank you for clarifying, no updates regarding that until now – have you made a feature request for this?

@Kaushik_Bhattacharya I see. In that scenario, please follow the instructions by @stayfoolish – as they said it, you need the bearer (authorization) token to get this to work.

@Mevi : as there is a workaround available, the feature didn’t seem to be first priority to me.

Actually, I would really love to see the development team concentration on the legion of ugly bugs first, before deploying any new features.
image
That’s where I feel the real pain!

1 Like

Alright then. And we are working on what we can! :sweat_smile:

I have already implemented @stayfoolish solution for Firestore security. My problem is the Firebase file upload component. I couldn’t figure out how to use the Id token here.

To POST a file works similar to POST a document:

Preparation: set the variable with the file to upload:
image
and
image
and


then

image
2.


3.
image

1 Like

Tx. Does this work if you pick multiple files in one go (that’s the way it’s set up in my app)? How does it work when I read the files? Right now it works with image view component in a simple way. How do I provide the auth token in that step?

Hi @stayfoolish

I have a question about your suggested solution, because I can’t upload images/files to Firebase Cloud Storage if request.auth != null; through the Firebase Upload Files flow function.

(I already have the authorization login through HTTP Request and all the stuff with the ID token, but if I use the firebase upload file flow function, I can’t pass the Id Token through it)

How is that you solve to upload a file to Firebase Cloud Storage through REST API?, can you share the flow function and some examples?

@Mevi do you know if there exists an update about this specific topic? thanks!

Thanks in advance.

The ‘Firebase Storage upload files’ doesn’t support authorization yet.
image

Instead you can use the ‘Upload files’ flow function in the way I described it above.
image

image

Oh, didnt see that part of the solution with the Upload Files flow function, I’m really sorry!.

Just in case, I did a double login to solve it meanwhile hehe, an auth login through HTTP Request, and firebase auth login flow function.

I did this way just because I need the ID Token, but I find out there is a new “Get firebase ID Token” flow function which can be used to obtain it with the firebase auth flow function, so what you suggest and that one I mentioned should work fine.

Thanks for your time to reply my question, really apprecciate.