Cloud FunctionsでFirebase Authenticationの認証情報を取得する

公開日時
更新日時

functions.https.onCall を使用している場合は context パラメータを受け取ることができ、 context.auth でリクエストユーザの認証情報が格納されている。

サンプル

import * as functions from 'firebase-functions'

const someFunction = functions
  .region('asia-northeast1')
  .https.onCall(async (data, context) => {
    if (!context.auth) {
      throw new functions.https.HttpsError('unauthenticated', 'unauthenticated')
    }

    const uid = context.auth.uid

    // uidに一致するfirestoreドキュメントを更新する、など
  })

export default someFunction

参考


Related #firebase

Firestoreの複合インデックスを削除する

CLI経由で削除する必要があった

Firebase Web SDK v9

_this.auth.addAuthTokenListener is not a function

8.6.5にダウングレードした

Firebase Summit 2021