Skip to content
Draft
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
15 changes: 11 additions & 4 deletions src/requireAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@
return authClient;
}

const nodeVersion = process.versions?.node;
const nodeMajorVersion = nodeVersion ? parseInt(nodeVersion.split(".")[0], 10) : 0;
const isNode22OrHigher = !isNaN(nodeMajorVersion) && nodeMajorVersion >= 22;
const transporterOptions = isNode22OrHigher
? config.clientOptions?.transporterOptions
: {
...config.clientOptions?.transporterOptions,
agent: apiv2.noKeepAliveAgent,
};

const authConfig: GoogleAuthOptions = {
...config,
clientOptions: {
...config.clientOptions,
transporterOptions: {
...config.clientOptions?.transporterOptions,
agent: apiv2.noKeepAliveAgent,
},
...(transporterOptions ? { transporterOptions } : {}),
},
};

Expand Down Expand Up @@ -88,7 +95,7 @@
return clientEmail || null;
}

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

Check warning on line 98 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Missing JSDoc comment
if (!lastOptions) {
throw new FirebaseError("Unable to refresh auth: not yet authenticated.");
}
Expand All @@ -103,20 +110,20 @@
* @param options CLI options.
*/
export async function requireAuth(
options: any,

Check warning on line 113 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type
skipAutoAuth: boolean = false,

Check warning on line 114 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Type boolean trivially inferred from a boolean literal, remove type annotation
): Promise<string | null> {
lastOptions = options;

Check warning on line 116 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe assignment of an `any` value
const requiredScopes = [scopes.CLOUD_PLATFORM];
if (isFirebaseStudio()) {
requiredScopes.push(scopes.USERINFO_EMAIL);
}
api.setScopes(requiredScopes);
options.authScopes = api.getScopes();

Check warning on line 122 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .authScopes on an `any` value

const tokens = options.tokens as Tokens | undefined;

Check warning on line 124 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (24)

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

Check warning on line 125 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (24)

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

Check warning on line 126 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe assignment of an `any` value
if (tokenOpt) {
logger.debug("> authorizing via --token option");
utils.logWarning(
Expand All @@ -135,7 +142,7 @@
return null;
} else {
try {
return await autoAuth(options, options.authScopes);

Check warning on line 145 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (24)

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

Check warning on line 145 in src/requireAuth.ts

View workflow job for this annotation

GitHub Actions / lint (24)

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
Loading