Skip to content
Merged
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
18 changes: 16 additions & 2 deletions js/plugins/firebase/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import { genkitPlugin, Plugin } from '@genkit-ai/core';
import { genkitPlugin, isDevEnv, Plugin } from '@genkit-ai/core';
import { logger } from '@genkit-ai/core/logging';
import { FirestoreStateStore } from '@genkit-ai/flow';
import {
GcpLogger,
Expand Down Expand Up @@ -43,7 +44,7 @@ export const firebase: Plugin<[FirestorePluginParams] | []> = genkitPlugin(
async (params?: FirestorePluginParams) => {
const authClient = new GoogleAuth();
const gcpOptions = {
projectId: params?.projectId || (await authClient.getProjectId()),
projectId: params?.projectId || (await getProjectId(authClient)),
telemetryConfig: params?.telemetryConfig,
};
return {
Expand All @@ -68,3 +69,16 @@ export const firebase: Plugin<[FirestorePluginParams] | []> = genkitPlugin(
};
}
);

async function getProjectId(authClient: GoogleAuth): Promise<string> {
if (isDevEnv()) {
return await authClient.getProjectId().catch((err) => {
logger.warn(
'WARNING: unable to determine Project ID, run "gcloud auth application-default login --project MY_PROJECT_ID"'
);
return '';
});
}

return await authClient.getProjectId();
}