Skip to content

Commit 147771a

Browse files
committed
rework parsing logic at server app init
1 parent 55b938b commit 147771a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/app/src/firebaseServerApp.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import { base64Decode } from '@firebase/util';
3030

3131
export class FirebaseServerAppImpl
3232
extends FirebaseAppImpl
33-
implements FirebaseServerApp {
33+
implements FirebaseServerApp
34+
{
3435
private readonly _serverConfig: FirebaseServerAppSettings;
3536
private _finalizationRegistry: FinalizationRegistry<object> | null;
3637
private _refCount: number;
@@ -69,17 +70,20 @@ export class FirebaseServerAppImpl
6970
};
7071

7172
// Parse the installationAuthToken if provided.
73+
this._installationsId = null;
7274
if (this._serverConfig.installationsAuthToken !== undefined) {
73-
const thirdPart = this._serverConfig.installationsAuthToken.split(".")[1].split(".")[0];
74-
const decodedToken = base64Decode(thirdPart);
75-
const tokenJSON = JSON.parse(decodedToken ? decodedToken : "");
76-
if (!decodedToken || !tokenJSON || tokenJSON.fid === undefined) {
77-
throw ERROR_FACTORY.create(AppError.INVALID_SERVER_APP_INSTALLATIONS_AUTH_TOKEN);
78-
} else {
75+
try {
76+
const decodedToken = base64Decode(
77+
this._serverConfig.installationsAuthToken.split('.')[1]
78+
);
79+
const tokenJSON = JSON.parse(decodedToken ? decodedToken : '');
7980
this._installationsId = tokenJSON.fid;
81+
} catch (e) {
82+
console.warn(e);
83+
}
84+
if (!this._installationsId) {
85+
console.error('INVALID SERVER APP INSTALLATIONS AUTH TOKEN!');
8086
}
81-
} else {
82-
this._installationsId = null;
8387
}
8488

8589
this._finalizationRegistry = null;

0 commit comments

Comments
 (0)