云函式的默認行為是否是以某種方式添加 stringyfy 值?使用以下函式獲取值時,我的時間戳結果會在物件中的鍵之前添加一個 _ 嗎?
await auth.currentUser ?
.getIdTokenResult()
.then((token: any) => {
// {_seconds : num, _nanoseconds : num}
console.log(token ? .claims.premiumUntill)
})
.catch((error: any) => {
console.log(error);
});
檢查檔案后,時間戳物件如下所示?
// Default
{seconds : number , nanoseconds : number}
// Recived
{_seconds : number , _nanoseconds : number}
云功能模型
admin
.auth()
.getUserByEmail(context.auth ? .token ? .email!)
.then((user) => admin.auth().setCustomUserClaims(user.uid, {
premiumUntill: admin.firestore.Timestamp.fromDate(createdAt)
})),
uj5u.com熱心網友回復:
云函式的默認行為是否是以某種方式添加 stringyfy 值?
是的,但這不是 Cloud Function 環境的行為。這是 Firebase Auth 自定義宣告的功能。如果你給它一個物件(比如時間戳),它會呼叫 toJSON 來獲取物件的 JSON 兼容表示,該表示適合存盤在自定義宣告中(只能存盤 JSON)。這就是你所看到的。您可能不應該依賴于此,而是將其轉換為更可預測的值,例如自紀元以來的毫秒數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/475468.html
標籤:javascript 节点.js 火力基地 谷歌云火库 谷歌云功能
