GRS
GRS

Reputation: 3084

How to link Firebase and GCP projects together?

We've recently created a GCP project and a Cloud Storage bucket in it.

Then we decided to use Firebase to host our React app. However, after creating the Firebase project (Why did we need to create a new project?), we got a different storage bucket. And it seems that it's not possible to view the same bucket from both projects.

Our backend uses a Cloud Storage bucket. Our frontend sends files to a Firestore bucket, which is different. How can we link it together?

Upvotes: 2

Views: 2121

Answers (2)

user3291025
user3291025

Reputation: 1117

You can use Firebase storage's getStorage function to specify the Google Cloud Storage Bucket. Then use gsutil to add the appropriate permissions between your Firebase project and the GCS bucket. You may need to edit the bucket permissions by going to Storage > Buckets and selecting Edit Bucket Permissions from the kebab menu (⋮) right of the bucket name. Here, you add can add the [email protected]

Frontend/browser Firebase code:

import { getApp } from "firebase/app";
import { getStorage } from "firebase/storage";

const firebaseApp = getApp();
const storage = getStorage(firebaseApp, "gs://my-custom-bucket");

command line to add permissions:

gsutil -m acl ch -r -u service-<project number>@gcp-sa-firebasestorage.iam.gserviceaccount.com gs://<my-custom-bucket>

The service-project number can be found in the Firebase project's console, under settings.

Upvotes: 0

Doug Stevenson
Doug Stevenson

Reputation: 317710

It's important to know that a Firebase project IS a Google Cloud project. Read more about that in this blog. Firebase is essentially a layer of APIs and services in a Google Cloud project. What you probably should have done in the first place is add Firebase to your existing Cloud project, but it's probably not worthwhile to do that if you already have an existing Firebase project.

There's really no way to link the projects together that would be convenient for you. What I recommend you do is abandon your first Cloud project, and copy the contents of your first bucket into your Firebase project default bucket. Also read more about the relationship between Firebase and Google Cloud with respect to Cloud Storage in this blog.

Upvotes: 3

Related Questions