第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Firebase 可調用函數(shù)上下文未定義

Firebase 可調用函數(shù)上下文未定義

胡子哥哥 2021-10-14 17:15:09
我根據(jù)此處的教程編寫了一個 firebase Http 可調用云函數(shù):https : //www.youtube.com/watch?v= 3hj_r_N0qMs from the firebase team。但是,我的函數(shù)無法驗證用戶(我)的自定義聲明,因為“context.auth”未定義我已將 firebase、firebase 工具、firebase-functions 和 admin SDK 更新到最新版本。我的函數(shù)/Index.ts 文件import * as functions from 'firebase-functions';import * as admin from 'firebase-admin';admin.initializeApp()export const addAdmin = functions.https.onCall((data, context) => {    if (context.auth.token.admin !== true) {        return {            error: 'Request not authorized'        };    }    const uid = data.uid    return grantAdminRole(uid).then(() => {        return {            result: `Request fulfilled!`        }    })})async function grantAdminRole(uid: string): Promise<void> {    const user = await admin.auth().getUser(uid);    if (user.customClaims && (user.customClaims as any).admin === true) {        console.log('already admin')        return;    }    return admin.auth().setCustomUserClaims(user.uid, {        admin: true,    }).then(() => {        console.log('made admin');    })}我的 app.component.ts 代碼makeAdmin() {    var addAdmin = firebase.functions().httpsCallable('addAdmin');    addAdmin({ uid: '[MY-USER-ID]' }).then(res => {      console.log(res);    })    .catch(error => {      console.log(error)    })  }如果我不嘗試訪問“上下文”并且我可以向該用戶添加自定義聲明,則該函數(shù)執(zhí)行良好。但是,如果我嘗試訪問 context.auth,則會發(fā)現(xiàn)錯誤:Unhandled error TypeError: Cannot read property 'token' of undefined"
查看完整描述

2 回答

?
收到一只叮咚

TA貢獻1821條經(jīng)驗 獲得超5個贊

錯誤消息告訴您context.auth沒有值。從API 文檔中可以看出,auth如果沒有經(jīng)過身份驗證的用戶發(fā)出請求,則為 null。這向我表明,您的客戶端應用程序在向可調用函數(shù)發(fā)出請求時沒有登錄用戶,因此請確保在調用該函數(shù)之前是這種情況。如果允許在沒有登錄用戶的情況下調用可調用函數(shù)的情況,則需要context.auth在代表該用戶執(zhí)行工作之前通過檢查來檢查函數(shù)代碼中的這種情況。


查看完整回答
反對 回復 2021-10-14
  • 2 回答
  • 0 關注
  • 180 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號