Skip to content

Add validation to check if project ID exists #8726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 24, 2025
Merged

Conversation

aalej
Copy link
Contributor

@aalej aalej commented Jun 8, 2025

Description

Fixes #5233

Adds an extra validation that checks if the project ID already exists. Give a warning message suggesting a different project ID if the one entered already exists.

Scenarios Tested

$ firebase init storage

     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:

  /Users/USER/Desktop/firebase-tools/issues/5233


=== Project Setup

First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add, 
but for now we'll just set up a default project.

✔ Please select an option: Create a new project
i  If you want to create a project in a Google Cloud organization or folder, please use "firebase projects:create" instead, and return to this command when you've created the project.
? Please specify a unique project id (warning: cannot be modified afterward) [6-30 characters]:
 test-project
> Project ID is taken or unavailable. Try test-project-9a3dd.
$ firebase init storage

     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:

  /Users/PATH/Desktop/firebase-tools/issues/5233


=== Project Setup

First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add, 
but for now we'll just set up a default project.

✔ Please select an option: Create a new project
i  If you want to create a project in a Google Cloud organization or folder, please use "firebase projects:create" instead, and return to this command when you've created the project.
✔ Please specify a unique project id (warning: cannot be modified afterward) [6-30 characters]:
 test-project-9a3dd
? What would you like to call your project? (defaults to your project ID) (test-project-9a3dd)

Sample Commands

Notes

The endpoint used for checking is /v1/projects:checkId, the issue is that we already have a Firebase API client that already exists, but that makes a call to /v1beta/projects:checkId

const firebaseAPIClient = new Client({
urlPrefix: api.firebaseApiOrigin(),
auth: true,
apiVersion: "v1beta1",
});

For us to be able to make a call to v1 endpoint, created a new client. Not sure if this is the best/cleanest solution here

const firebaseV1APIClient = new Client({
  urlPrefix: api.firebaseApiOrigin(),
  auth: true,
  apiVersion: "v1",
});

@aalej aalej changed the title Add validation to check if project ID exists [DRAFT] Add validation to check if project ID exists Jun 8, 2025
@aalej aalej marked this pull request as draft June 8, 2025 17:33
@aalej aalej marked this pull request as ready for review June 19, 2025 22:25
@aalej aalej changed the title [DRAFT] Add validation to check if project ID exists Add validation to check if project ID exists Jun 20, 2025
@aalej aalej requested a review from joehan June 20, 2025 11:12
@aalej aalej enabled auto-merge (squash) June 24, 2025 11:36
@aalej aalej merged commit 2c576e6 into master Jun 24, 2025
49 of 50 checks passed
@aalej aalej deleted the aalej-pidexistscheck branch June 24, 2025 11:46
@github-project-automation github-project-automation bot moved this from Approved [PR] to Done in [Cloud] Extensions + Functions Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

firebase init fails: project id already exists
2 participants