注意
自分用のメモとしての意味合いが強いので、簡単に記載しています。
前提として、Firebase CLIなどのインストールは済んでいるものとします。
事象
firebase init functions
がHTTP Error: 401, Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.
で失敗する
https://stackoverflow.com/a/52891586 を参考に、一度firebase logout
でログアウトしてからfirebase login
でログインし直したところ解決しました。
firebase deploy --only functions
がError: An unexpected error has occurred.
と表示されて失敗する
https://stackoverflow.com/a/56885970 を参考にnpm install -g npm@6.9.2
を実行することで解決しました。
firebase deploy --only functions
が成功してもFirebaseコンソールに反映されない
最初に生成されたサンプルコードをそのままデプロイしていたのが原因でした。
index.js
const functions = require('firebase-functions');
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// });
コメントアウトを外したら反映されました。
index.js
const functions = require('firebase-functions');
// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});