Create a context.auth (1st Gen) equivalent for 2nd Gen cloud function
1st gen cloud functions can access auth info via context.auth as described here: https://firebase.google.com/docs/database/extend-with-functions?gen=1st#accessing_user_authentication_information
But 2nd gen cloud functions is yet to have the same function.
-
Tomáš Bezouška commented
We have an existing app which heavily depends on this. We use it mainly to run functions in the user's context - they can write to the DB a lot and we want security rules to apply (a single bug in the function could could destroy the entire database, since by default admin.database() bypasses rules)
-
Hassan El Khalifte commented
We strongly need this in our projects
V2 functions with relatime database triggers must have event.auth as in 1st generation (context.auth)
We are still using V1 functions just because of this !!
-
Carlos Ernesto Chan Martinez commented
This change is crucial for my work. I’ve been using it to track changes in the changelog of some nodes in my real-time database. I was preparing to update the version of my functions, but I am unable to proceed due to this issue. We also use the context.timestamp for some versioning procedure, so it would be extremely helpful to have that available as well.
-
Kazuyuki Arai commented
Strongly agree that this makes migration to v2 very cumbersome, and also pollutes the data structure in an unfortunate way. Really hope this will be fixed soon!
-
Zach Malguitou commented
This is indeed very much needed for Gen 2 in my view. Without it there is no "easy" migraton to Gen 2 functions and rather more involved workarounds needed to ensure functions are only invoked by the intended users.
-
Luiz Americo Pereira Camara commented
The title is not accurate. context.auth is only provided in realtime database event handlers.
Cloud Functions Firestore triggers (the equivalent to realtime database event handlers) do not have context.auth neither in 1st gen nor in 2nd gen.
A more accurate title would be "Create a context.auth for firestore triggers like in realtime database event handlers"
Also, this is same as https://firebase.uservoice.com/forums/948424-general/suggestions/46611049-auth-oncreate-and-ondelete-triggers-for-v2-functio
As for use case, i need this feature to create audit logs (who created, deleted, updated an entity). Currently i need to pass the user id in every call that updates data, polluting the document structure.