Firestore - Cloud Functions - Get uid

前端 未结 2 1914
半阙折子戏
半阙折子戏 2020-12-06 02:35

I\'m trying to get the UID of the user authenticated by firebase web sdk, in the cloud function. The cloud function is triggered by onWrite event of cloud fires

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 02:44

    Since Cloud Functions 1.0 you can get the UID like this

    exports.dbCreate = functions.database.ref('/path').onCreate((snap, context) => {
      const uid = context.auth.uid;
      const authVar = context.auth; 
    });
    

    Here is a nice post from the FB team for all CF1.0 changes: https://firebase.google.com/docs/functions/beta-v1-diff#event_parameter_split_into_data_and_context

    The data of context.auth can be found here: https://firebase.google.com/docs/firestore/reference/security/#properties

提交回复
热议问题