Skip to content

Commit ca6e1ee

Browse files
Throw a more helpful error if there isn't a 'sub' field (#1366)
* Throw a more helpful error if there isn't a 'sub' field * fix test
1 parent c1cae8f commit ca6e1ee

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/testing/src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ function createUnsecuredJwt(auth: object): string {
6363
(auth as any).iat = (auth as any).iat || 0;
6464
// Use `uid` field as a backup when `sub` is missing.
6565
(auth as any).sub = (auth as any).sub || (auth as any).uid;
66+
if (!(auth as any).sub) {
67+
throw new Error("auth must be an object with a 'sub' or 'uid' field");
68+
}
6669
// Unsecured JWTs use the empty string as a signature.
6770
const signature = '';
6871
return [

packages/testing/test/database.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ describe('Testing Module Tests', function() {
117117

118118
it('apps() returns apps created with initializeTestApp', async function() {
119119
const numApps = firebase.apps().length;
120-
await firebase.initializeTestApp({ databaseName: 'foo', auth: {} });
120+
await firebase.initializeTestApp({ databaseName: 'foo', auth: null });
121121
expect(firebase.apps().length).to.equal(numApps + 1);
122-
await firebase.initializeTestApp({ databaseName: 'bar', auth: {} });
122+
await firebase.initializeTestApp({ databaseName: 'bar', auth: null });
123123
expect(firebase.apps().length).to.equal(numApps + 2);
124124
});
125125

0 commit comments

Comments
 (0)