Skip to content

Commit 25098bf

Browse files
Fixes optional fields in UserRecord types to be optional. (#421)
* Fixes optional fields in UserRecord types to be optional. References will be updated to reflect that too. * Fixes UserRecord#tokensValidAfterTime to be undefined instead of null when not available. * Added CHANGELOG note.
1 parent e19fc51 commit 25098bf

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unreleased
22

3-
-
3+
- [fixed] Fixed optional fields in UserRecord types to be optional.
44

55
# v6.4.0
66

src/auth/user-record.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class UserRecord {
186186
if (typeof response.validSince !== 'undefined') {
187187
validAfterTime = parseDate(response.validSince * 1000);
188188
}
189-
utils.addReadonlyGetter(this, 'tokensValidAfterTime', validAfterTime);
189+
utils.addReadonlyGetter(this, 'tokensValidAfterTime', validAfterTime || undefined);
190190
}
191191

192192
/** @return {object} The plain object representation of the user record. */

src/index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ declare namespace admin.auth {
104104

105105
interface UserRecord {
106106
uid: string;
107-
email: string;
107+
email?: string;
108108
emailVerified: boolean;
109-
displayName: string;
110-
phoneNumber: string;
111-
photoURL: string;
109+
displayName?: string;
110+
phoneNumber?: string;
111+
photoURL?: string;
112112
disabled: boolean;
113113
metadata: admin.auth.UserMetadata;
114114
providerData: admin.auth.UserInfo[];

test/unit/auth/auth.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ describe('Auth', () => {
456456
const noValidSinceExpectedUserRecord =
457457
getValidUserRecord(noValidSinceGetAccountInfoResponse);
458458
// Confirm null tokensValidAfterTime on user.
459-
expect(noValidSinceExpectedUserRecord.tokensValidAfterTime).to.be.null;
459+
expect(noValidSinceExpectedUserRecord.tokensValidAfterTime).to.be.undefined;
460460
// Simulate getUser returns the expected user with no validSince.
461461
const getUserStub = sinon.stub(Auth.prototype, 'getUser')
462462
.returns(Promise.resolve(noValidSinceExpectedUserRecord));
@@ -660,7 +660,7 @@ describe('Auth', () => {
660660
const noValidSinceExpectedUserRecord =
661661
getValidUserRecord(noValidSinceGetAccountInfoResponse);
662662
// Confirm null tokensValidAfterTime on user.
663-
expect(noValidSinceExpectedUserRecord.tokensValidAfterTime).to.be.null;
663+
expect(noValidSinceExpectedUserRecord.tokensValidAfterTime).to.be.undefined;
664664
// Simulate getUser returns the expected user with no validSince.
665665
const getUserStub = sinon.stub(Auth.prototype, 'getUser')
666666
.returns(Promise.resolve(noValidSinceExpectedUserRecord));

test/unit/auth/user-record.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ describe('UserRecord', () => {
546546
}).to.throw(Error);
547547
});
548548

549-
it('should return null tokensValidAfterTime when not available', () => {
550-
expect(userRecordNoValidSince.tokensValidAfterTime).to.be.null;
549+
it('should return undefined tokensValidAfterTime when not available', () => {
550+
expect(userRecordNoValidSince.tokensValidAfterTime).to.be.undefined;
551551
});
552552

553553
it('should return expected metadata', () => {
@@ -637,8 +637,8 @@ describe('UserRecord', () => {
637637
expect(userRecord.toJSON()).to.deep.equal(getUserJSON());
638638
});
639639

640-
it('should return null tokensValidAfterTime when not available', () => {
641-
expect((userRecordNoValidSince.toJSON() as any).tokensValidAfterTime).to.be.null;
640+
it('should return undefined tokensValidAfterTime when not available', () => {
641+
expect((userRecordNoValidSince.toJSON() as any).tokensValidAfterTime).to.be.undefined;
642642
});
643643
});
644644
});

0 commit comments

Comments
 (0)