Skip to content

Commit cb90fab

Browse files
authored
Fix common identity package internal toJSON function (#1125)
* fixing the toJSON function * fix nit * adding changelog
1 parent 27a4983 commit cb90fab

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixes bug where `toJSON` was not defined in `UserRecord` (#1125).

spec/common/providers/identity.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,34 @@ describe('identity', () => {
8888
lastSignInTime: '2017-02-02T23:01:19.797Z',
8989
});
9090
});
91+
92+
it('should stringify the record', () => {
93+
const raw: any = {
94+
uid: '123',
95+
96+
emailVerified: true,
97+
displayName: 'User',
98+
photoURL: 'url',
99+
phoneNumber: '1233332222',
100+
disabled: true,
101+
providerData: ['something'],
102+
customClaims: {
103+
claim: 'value',
104+
another: {
105+
inner: 'value',
106+
},
107+
},
108+
passwordSalt: 'abc',
109+
passwordHash: 'def',
110+
tokensValidAfterTime: '2027-02-02T23:01:19.797Z',
111+
metadata: {
112+
creationTime: '2017-02-02T23:06:26.124Z',
113+
lastSignInTime: '2017-02-02T23:01:19.797Z',
114+
},
115+
};
116+
const record = identity.userRecordConstructor(raw);
117+
expect(() => JSON.stringify(record)).to.not.throw;
118+
});
91119
});
92120

93121
describe('isValidRequest', () => {

src/common/providers/identity.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ export function userRecordConstructor(wireData: Object): UserRecord {
146146
};
147147
json.metadata = record.metadata.toJSON();
148148
json.customClaims = JSON.parse(JSON.stringify(record.customClaims));
149-
json.providerData = record.providerData.map((entry) => entry.toJSON());
149+
json.providerData = record.providerData.map((entry) => {
150+
const newEntry = { ...entry };
151+
newEntry.toJSON = () => entry;
152+
return newEntry;
153+
});
150154
return json;
151155
};
152156
return record as UserRecord;

0 commit comments

Comments
 (0)