Couldn't deploy functions on Firebase Cloud Functions

Viewed 54

I divided the files by each function in developing the Firebase Cloud Functions. However, a lot of errors occurred and the code couldn't be deployed.

Error

[debug] [2022-07-19T14:36:17.677Z] <<< [apiv2][body] GET https://us.gcr.io/v2/xxxxxx/gcf/us-central1/tags/list {"errors":[{"code":"DENIED","message":"Failed to read tags for host 'us.gcr.io', repository '/v2/xxxxxxxxxx/gcf/us-central1/tags/list'"}]}
[debug] [2022-07-19T14:36:17.678Z] Failed docker command with error  HTTP Error: 403, Unknown Error {"name":"FirebaseError","children":[],"context":{"body":{"errors":[{"code":"DENIED","message":"Failed to read tags for host 'us.gcr.io', repository '/v2/xxxxxxxxxx/gcf/us-central1/tags/list'"}],"error":{"message":"Unknown Error"}},"response":{"statusCode":403}},"exit":1,"message":"HTTP Error: 403, Unknown Error","status":403}
[error] - Error Failed to update function createUser in region us-central1

Code

index.ts

import { onCreate } from './firebase'
export const createUser = onCreate(`companies/{companyId}/users/{userId}`, 'userCreate')

triggers/userCreate.ts

/* eslint-disable */

import type { Snapshot } from "../firebase"
import { SLACK_WEBHOOK_URL } from "../config"
import { SlackService } from "../services/SlackService"
import { createdUserMessage } from "../utilities/slackMessages";

export const trigger = async (snapshot: Snapshot) => {
  const user = snapshot.data()
  const message = createdUserMessage(user)
  await SlackService.sendSlackNotification(SLACK_WEBHOOK_URL, message)
};

firebase.ts

import * as functions from 'firebase-functions';

export type Snapshot = functions.firestore.QueryDocumentSnapshot;
export type Context = functions.EventContext;

type SnapshotHandler = { trigger: (snapshot: Snapshot, context: Context) => Promise<unknown> };

const getHandler = async (handlerFileName: string) => {
  const handlerFilePath = `./triggers/${handlerFileName}`;
  return await import(handlerFilePath);
};

const db = functions.region('us-central1').firestore;

export const onCreate = (documentPath: string, handlerFileName: string) => {
  return db.document(documentPath).onCreate(async (snapshot, context) => {
    const handler: SnapshotHandler = await getHandler(handlerFileName);
    return handler.trigger(snapshot, context);
  });
};
1 Answers

Updating to the latest version of Firebase CLI could fix it.

npm install -g firebase-tools@latest

Also go here and make sure you have an owner or editor role in the Firebase project.

Related