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