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.
-
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.