@@ -100,26 +100,35 @@ export function initializeFirebase(adminInstance: any): admin.app.App {
100
100
} else {
101
101
// Get service account from local file falling back to environment variables
102
102
const serviceAccount = getServiceAccount ( ) ;
103
- const projectId = serviceAccount ?. project_id ;
103
+ const projectId =
104
+ process . env . GCLOUD_PROJECT || serviceAccount ?. project_id ;
104
105
if ( ! isString ( projectId ) ) {
105
106
const missingProjectIdErr =
106
- 'Error project_id from service account to initialize Firebase.' ;
107
+ 'Error GCLOUD_PROJECT environment variable or project_id from service account to initialize Firebase.' ;
107
108
console . error ( `cypress-firebase: ${ missingProjectIdErr } ` ) ; // eslint-disable-line no-console
108
109
throw new Error ( missingProjectIdErr ) ;
109
110
}
110
111
const cleanProjectId = ( projectId as string ) . replace (
111
112
'firebase-top-agent-int' ,
112
113
'top-agent-int' ,
113
114
) ;
115
+
116
+ const appSettings : any = {
117
+ databaseURL : `https://${ cleanProjectId } .firebaseio.com` ,
118
+ } ;
119
+
120
+ if ( serviceAccount ) {
121
+ appSettings . credential = adminInstance . credential . cert (
122
+ serviceAccount as any ,
123
+ ) ;
124
+ }
125
+
126
+ fbInstance = adminInstance . initializeApp ( appSettings ) ;
114
127
/* eslint-disable no-console */
115
128
console . log (
116
- `cypress-firebase: Initialized with Service Account for project "${ cleanProjectId } "` ,
129
+ `cypress-firebase: Initialized app with project "${ cleanProjectId } "` ,
117
130
) ;
118
131
/* eslint-enable no-console */
119
- fbInstance = adminInstance . initializeApp ( {
120
- credential : adminInstance . credential . cert ( serviceAccount as any ) ,
121
- databaseURL : `https://${ cleanProjectId } .firebaseio.com` ,
122
- } ) ;
123
132
}
124
133
125
134
return fbInstance ;
0 commit comments