[英]Firebase Cloud Function, how can I access parent data after onCreate event triggered?
[英]How can I access firebase custom claims from a cloud function
編輯:我可以按照下面的方式進行,但我更喜歡更好的解決方案:
console.log((operatorUser.customClaims as any)['admin']);
console.log((operatorUser.customClaims as any).admin);
我正在嘗試檢查可調用雲 function 中的用戶自定義聲明。
嘗試訪問自定義聲明時出現以下錯誤:
“元素隱式具有“任何”類型,因為類型“admin”的表達式不能用於索引類型“Object”。屬性“admin”在類型“Object”上不存在”
const operatorUser = await admin.auth().getUser(operatorUserDoc.id);
console.log(operatorUser.customClaims['admin']);
謝謝。 這幫助我解決了另一個相關問題。
僅供參考,在 firebase“實時數據庫”雲 function 中訪問調用用戶聲明的另一種方法是直接來自 context.auth:
const isAdmin = (context?.auth?.token as any)?.admin;
最近改進了customClaims
的類型簽名。 如果您使用的是 SDK 的最新版本,您應該可以只執行user['key']
來訪問聲明。
有關更多上下文,請參閱https://github.com/firebase/firebase-admin-node/issues/864 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.