I am trying to get the UID of a firebase web sdk authenticated user in a cloud function. The cloud function is triggered by a onWritecloud firestore event .
This function is triggered when a logged-in user creates or updates items in a cafe. Authentication is being processed Firebase Auth. Security rules allow writing only for registered users. Thus, this event can be associated with the user.
export const cfun = functions.firestore.document('cafes/{cafeId}/items/{itemId}').onWrite(async event => {
})
There userIdare examples in the documents dealing with , but in all of these cases, userId is part of the path to the document. But in this model, the user is not part of the path, since the cafe can have several owners and therefore can manipulate many users. Therefore, adding userId to the path is not an option.
It looks like a normal case of serverless architecture.
#
Update: functions launched by firestore do not have event.auth. Look for suggestions for modeling the following requirement.
. , . , /cafes/{cafeId} , /cafes/{cafeId}/items/{itemId} ..
, . /users/{userId}/cafes/{cafeId}.
, get(<>), , . .
, . userId .
event.auth , , /users/{userId}/<item_name>/{itemId}, userId . .
, - , . event.auth, firebase, .
, , .
#
,