Skip to content

Adding global default project when running on firebase studio #8830

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/requireAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@

// project is also selected in monospace auth flow
options.projectId = await client.getProjectId();
// Persist this project so it is used by other commands, too.
utils.setGlobalDefaultProject(options.projectId);
}
return clientEmail || null;
}

export async function refreshAuth(): Promise<Tokens> {

Check warning on line 73 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
if (!lastOptions) {
throw new FirebaseError("Unable to refresh auth: not yet authenticated.");
}
Expand All @@ -82,14 +84,14 @@
* if the user is not authenticated
* @param options CLI options.
*/
export async function requireAuth(options: any): Promise<string | null> {

Check warning on line 87 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
lastOptions = options;

Check warning on line 88 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
api.setScopes([scopes.CLOUD_PLATFORM, scopes.FIREBASE_PLATFORM]);
options.authScopes = api.getScopes();

Check warning on line 90 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .authScopes on an `any` value

const tokens = options.tokens as Tokens | undefined;

Check warning on line 92 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .tokens on an `any` value
const user = options.user as User | undefined;

Check warning on line 93 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .user on an `any` value
let tokenOpt = utils.getInheritedOption(options, "token");

Check warning on line 94 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
if (tokenOpt) {
logger.debug("> authorizing via --token option");
utils.logWarning(
Expand All @@ -106,7 +108,7 @@
logger.debug(`> authorizing via signed-in user (${user.email})`);
} else {
try {
return await autoAuth(options, options.authScopes);

Check warning on line 111 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .authScopes on an `any` value

Check warning on line 111 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string[]`

Check warning on line 111 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `Options`
} catch (e: any) {
throw new FirebaseError(
`Failed to authenticate, have you run ${clc.bold("firebase login")}?`,
Expand Down
13 changes: 13 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,19 @@
configstore.set("activeProjects", activeProjects);
}

/**
* Sets the global default project.
* When no other project is specified (either via the current directory or the --project flag),
* this project will be used.
*/
export function setGlobalDefaultProject(project: string): void {
configstore.set("globalDefaultProject", project);
logger.info("");
logger.info(`${clc.bold(project)} is now your global default project.`);
logger.info("When no other project is specified (by 'firebase use' or '--project'), this project will be used.");

Check failure on line 352 in src/utils.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `"When·no·other·project·is·specified·(by·'firebase·use'·or·'--project'),·this·project·will·be·used."` with `⏎····"When·no·other·project·is·specified·(by·'firebase·use'·or·'--project'),·this·project·will·be·used.",⏎··`

Check failure on line 352 in src/utils.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Replace `"When·no·other·project·is·specified·(by·'firebase·use'·or·'--project'),·this·project·will·be·used."` with `⏎····"When·no·other·project·is·specified·(by·'firebase·use'·or·'--project'),·this·project·will·be·used.",⏎··`

Check failure on line 352 in src/utils.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `"When·no·other·project·is·specified·(by·'firebase·use'·or·'--project'),·this·project·will·be·used."` with `⏎····"When·no·other·project·is·specified·(by·'firebase·use'·or·'--project'),·this·project·will·be·used.",⏎··`

Check failure on line 352 in src/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `"When·no·other·project·is·specified·(by·'firebase·use'·or·'--project'),·this·project·will·be·used."` with `⏎····"When·no·other·project·is·specified·(by·'firebase·use'·or·'--project'),·this·project·will·be·used.",⏎··`
Comment on lines +351 to +352

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other CLI output, consider using the existing logging helper functions like logSuccess and logBullet. This will provide a more familiar user experience with status indicators (e.g., checkmarks).

logSuccess will add a prefix, and logBullet will add an i prefix, which is common for informational messages in this CLI.

Suggested change
logger.info(`${clc.bold(project)} is now your global default project.`);
logger.info("When no other project is specified (by 'firebase use' or '--project'), this project will be used.");
logSuccess(`${clc.bold(project)} is now your global default project.`);
logBullet("When no other project is specified (by 'firebase use' or '--project'), this project will be used.");

logger.info("");
}

/**
* Creates API endpoint string, e.g. /v1/projects/pid/cloudfunctions
*/
Expand Down
Loading