Skip to content

Commit

Permalink
Fix common identity package internal toJSON function (#1125)
Browse files Browse the repository at this point in the history
* fixing the toJSON function

* fix nit

* adding changelog
  • Loading branch information
colerogers committed May 16, 2022
1 parent 27a4983 commit cb90fab
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixes bug where `toJSON` was not defined in `UserRecord` (#1125).
28 changes: 28 additions & 0 deletions spec/common/providers/identity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,34 @@ describe('identity', () => {
lastSignInTime: '2017-02-02T23:01:19.797Z',
});
});

it('should stringify the record', () => {
const raw: any = {
uid: '123',
email: 'email@gmail.com',
emailVerified: true,
displayName: 'User',
photoURL: 'url',
phoneNumber: '1233332222',
disabled: true,
providerData: ['something'],
customClaims: {
claim: 'value',
another: {
inner: 'value',
},
},
passwordSalt: 'abc',
passwordHash: 'def',
tokensValidAfterTime: '2027-02-02T23:01:19.797Z',
metadata: {
creationTime: '2017-02-02T23:06:26.124Z',
lastSignInTime: '2017-02-02T23:01:19.797Z',
},
};
const record = identity.userRecordConstructor(raw);
expect(() => JSON.stringify(record)).to.not.throw;
});
});

describe('isValidRequest', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/common/providers/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ export function userRecordConstructor(wireData: Object): UserRecord {
};
json.metadata = record.metadata.toJSON();
json.customClaims = JSON.parse(JSON.stringify(record.customClaims));
json.providerData = record.providerData.map((entry) => entry.toJSON());
json.providerData = record.providerData.map((entry) => {
const newEntry = { ...entry };
newEntry.toJSON = () => entry;
return newEntry;
});
return json;
};
return record as UserRecord;
Expand Down

0 comments on commit cb90fab

Please sign in to comment.