Skip to content

Commit e8900fe

Browse files
authored
Handle case where the server does not return an FID (#1936)
1 parent 634f84d commit e8900fe

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

packages/installations/src/api/create-installation.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ describe('createInstallation', () => {
105105
});
106106
});
107107

108+
it('returns the FID from the request if the response does not contain one', async () => {
109+
response = {
110+
refreshToken: 'refreshToken',
111+
authToken: {
112+
token:
113+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
114+
expiresIn: '604800s'
115+
}
116+
};
117+
fetchSpy.resolves(new Response(JSON.stringify(response)));
118+
119+
const registeredInstallationEntry = await createInstallation(
120+
appConfig,
121+
inProgressInstallationEntry
122+
);
123+
expect(registeredInstallationEntry.fid).to.equal(FID);
124+
});
125+
108126
describe('failed request', () => {
109127
it('throws a FirebaseError with the error information from the server', async () => {
110128
const errorResponse: ErrorResponse = {

packages/installations/src/api/create-installation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function createInstallation(
5555
if (response.ok) {
5656
const responseValue: CreateInstallationResponse = await response.json();
5757
const registeredInstallationEntry: RegisteredInstallationEntry = {
58-
fid: responseValue.fid,
58+
fid: responseValue.fid || fid,
5959
registrationStatus: RequestStatus.COMPLETED,
6060
refreshToken: responseValue.refreshToken,
6161
authToken: extractAuthTokenInfoFromResponse(responseValue.authToken)

packages/installations/src/interfaces/api-response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
export interface CreateInstallationResponse {
1919
readonly refreshToken: string;
2020
readonly authToken: GenerateAuthTokenResponse;
21-
readonly fid: string;
21+
readonly fid?: string;
2222
}
2323

2424
export interface GenerateAuthTokenResponse {

0 commit comments

Comments
 (0)