Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix common identity package internal toJSON function #1125

Merged
merged 3 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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