長野エンジニアライフ

東京から長野に移住したエンジニアのブログです。🦒🗻⛰

【Firebase】Functionからstorageの署名付きURLを取得しようとしたら Error: Permission iam.serviceAccounts.signBlob is required to perform this operation on service account projects

事象

[Firebase] Functionからstorageの署名付きURLを取得しようとしたら 以下のエラーが発生(コンソール画面からIAM APIは有効に設定済み)

Error: Permission iam.serviceAccounts.signBlob is required to perform this operation on service account projects

原因

対象projectに対するservice accountが未設定のため上記エラーが発生

対応方針

コンソール画面にて、対象プロジェクトに対してサービスアカウントトークン作成者の権限を付与する

参考記事

cheerio-the-bear.hatenablog.com

【Firebase】Functionからstorageの署名付きURLを取得しようとしたら Error: Identity and Access Management (IAM) API has not been used in project XXXXX

事象

Functionからstorageの署名付きURLを取得しようとしたら以下のエラーが発生した。

Error: Identity and Access Management (IAM) API has not been used in project

原因

GCPのコンソールにて、Management (IAM) APIが無効になっていたことが原因。

f:id:kawakeee:20200610002950p:plain

対応方針

エラー全文を読むとコンソール画面のURLが記載されているのでコンソール画面から有効にしてあげると上記エラーが消えた。

参考記事

cheerio-the-bear.hatenablog.com

Error: @grpc/grpc-js only works on Node ^8.13.0 || >=10.10.0の対応

起こったこと

firebaseのfunctionをデプロイしたら以下のエラーが発生

✔  functions: Finished running predeploy script.
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...

Error: Error occurred while parsing your function triggers.

Error: @grpc/grpc-js only works on Node ^8.13.0 || >=10.10.0

原因

nodenvでバージョンが* 9.10.1を使用していた

対応

node環境8.13.0に合わせてデプロイを行う

  • 8.13.0をインストール
nodenv install 8.13.0
  • バージョンの切り替え
nodenv global 8.13.0

切り替え後、本エラーが吐かれずにdeployできた。

参考記事

github.com

firebase.google.com

joppot.info

TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_13___default.a.storage is not a function

事象

storageから画像を参照すると以下のエラーが発生

TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_13___default.a.storage is not a function

原因/対応

firebaseの設定ファイルでimport 'firebase/storage'のimport文が必要のため追加した

参考記事

qiita.com

Options props is deprecated, add sortable options directly as vue.draggable item, or use v-bind.の警告を消したい。

やりたいこと

以下の警告を消したい。

Options props is deprecated, add sortable options directly as vue.draggable item, or use v-bind.

optionsを渡すのは非推奨

以下のように、propsでoptionsをしているのは非推奨のようで、そのままv-bindしてあげればよかった。

    <draggable
      v-model="filterList"
      v-bind:options="{
        animation: 200,
        delay: 100
      }"
    >

対応

以下のように:optionsを消したら警告も消えた。

    <draggable
      v-model="filterList"
      v-bind="{
        animation: 200,
        delay: 100
      }"
    >

Firestoreに一括で更新を行う

やりたいこと

Firestoreにて、複数のドキュメントに対して一括で更新を行いたい。

バッチ書き込みを利用

.batch()で生成したオブジェクトにupdateしたいパスとオブジェクトをガンガン足していく。batch.commit()したタイミングで一括実行される。

import firebase from 'firebase/app'
import firestore from '@/firebase/firebase'
...

const batch = firestore.batch()

cardList.forEach(card => {
  const cardRef = firestore.collection('card').doc(card.id)
  batch.update(cardRef, { index: card.newIndex })
})

batch.commit()

参考

cloud.google.com