@@ -33,34 +33,28 @@ export class AppStore {
3333 public initializeApp ( options ?: AppOptions , appName : string = DEFAULT_APP_NAME ) : App {
3434 validateAppNameFormat ( appName ) ;
3535
36- console . error ( 'initializeApp options: ' , options ) ;
37-
3836 let autoInit = false ;
3937 if ( typeof options === 'undefined' ) {
4038 autoInit = true
4139 options = loadOptionsFromEnvVar ( ) ;
4240 options . credential = getApplicationDefault ( ) ;
4341 }
4442
45- console . error ( 'DEDB 1' ) ;
46-
43+ // Check to see if an App already exists. And validate that we can return it
44+ // given the AppOptions parameter provided to initializeApp.
4745 if ( this . appStore . has ( appName ) ) {
48- console . error ( 'DEDB 2' ) ;
4946 const currentApp = this . appStore . get ( appName ) ! ;
50- console . error ( 'DEDB 3' ) ;
5147 if ( currentApp . autoInit ( ) !== autoInit ) {
52- console . error ( 'DEDB 4' ) ;
5348 throw new FirebaseAppError (
5449 AppErrorCodes . INVALID_ARGUMENT ,
5550 `Firebase app named "${ appName } " attempted mismatch between custom AppOptions` +
5651 ' and an App created via Auto Init.'
5752 )
5853 } else if ( autoInit ) {
59- console . error ( 'DEDB 5' ) ;
6054 return currentApp ;
6155 } else {
62- console . error ( 'DEDB 6' ) ;
63-
56+ // httpAgent breaks idempotency. Throw if the AppOptions parameter or the
57+ // existing app contains a httpAgent.
6458 if ( typeof options . httpAgent !== 'undefined' ) {
6559 throw new FirebaseAppError (
6660 AppErrorCodes . INVALID_APP_OPTIONS ,
@@ -77,6 +71,9 @@ export class AppStore {
7771 ) ;
7872 }
7973
74+ // Credential breaks idempotency. Throw if the AppOptions parameter contains a
75+ // Credential, or if the existing app's credential was provided during its
76+ // construction.
8077 if ( typeof options . credential !== 'undefined' ) {
8178 throw new FirebaseAppError (
8279 AppErrorCodes . INVALID_APP_OPTIONS ,
@@ -93,19 +90,13 @@ export class AppStore {
9390 ) ;
9491 }
9592
93+ // FirebaseApp appends credentials to the options upon construction. Remove
94+ // those generated credentials for the sake of AppOptions parameter comparison.
9695 const currentAppOptions = { ...currentApp . options } ;
9796 delete currentAppOptions . credential ;
98-
99- console . error ( 'DEDB 9' ) ;
100- console . error ( 'options: ' , options ) ;
101- console . error ( 'existingApp.options: ' , currentAppOptions ) ;
102- console . error ( 'equals: ' , deepEqual ( options , currentAppOptions ) ) ;
103-
10497 if ( deepEqual ( options , currentAppOptions ) ) {
105- console . error ( 'DEDB 10' ) ;
10698 return currentApp ;
10799 } else {
108- console . error ( 'DEDB 11' ) ;
109100 throw new FirebaseAppError (
110101 AppErrorCodes . DUPLICATE_APP ,
111102 `A Firebase app named "${ appName } " already exists with a different options` +
@@ -115,11 +106,8 @@ export class AppStore {
115106 }
116107 }
117108
118- console . error ( 'DEDB 12' ) ;
119-
120109 const app = new FirebaseApp ( options , appName , autoInit , this ) ;
121110 this . appStore . set ( app . name , app ) ;
122- console . error ( 'DEDB returning app with options: ' , app . options ) ;
123111 return app ;
124112 }
125113
0 commit comments