diff --git a/etc/firebase-admin.auth.api.md b/etc/firebase-admin.auth.api.md index 768cd26b8a..82ac60b019 100644 --- a/etc/firebase-admin.auth.api.md +++ b/etc/firebase-admin.auth.api.md @@ -195,7 +195,7 @@ export abstract class MultiFactorInfo { // @public export class MultiFactorSettings { enrolledFactors: MultiFactorInfo[]; - toJSON(): any; + toJSON(): object; } // @public @@ -394,7 +394,7 @@ export class UserInfo { // @public export class UserMetadata { readonly creationTime: string; - readonly lastRefreshTime: string | null; + readonly lastRefreshTime?: string | null; readonly lastSignInTime: string; toJSON(): object; } diff --git a/src/auth/user-record.ts b/src/auth/user-record.ts index 86dadc07f9..da55540b56 100644 --- a/src/auth/user-record.ts +++ b/src/auth/user-record.ts @@ -78,6 +78,7 @@ export interface GetAccountInfoUserResponse { mfaInfo?: MultiFactorInfoResponse[]; createdAt?: string; lastLoginAt?: string; + lastRefreshAt?: string; [key: string]: any; } @@ -277,7 +278,7 @@ export class MultiFactorSettings { /** * @return A JSON-serializable representation of this multi-factor object. */ - public toJSON(): any { + public toJSON(): object { return { enrolledFactors: this.enrolledFactors.map((info) => info.toJSON()), }; @@ -304,7 +305,7 @@ export class UserMetadata { * formatted as a UTC Date string (eg 'Sat, 03 Feb 2001 04:05:06 GMT'). * Returns null if the user was never active. */ - public readonly lastRefreshTime: string | null; + public readonly lastRefreshTime?: string | null; /** * @param response The server side response returned from the getAccountInfo diff --git a/test/unit/auth/user-record.spec.ts b/test/unit/auth/user-record.spec.ts index 2e1e3286c9..cca0af6185 100644 --- a/test/unit/auth/user-record.spec.ts +++ b/test/unit/auth/user-record.spec.ts @@ -685,6 +685,15 @@ describe('UserMetadata', () => { it('should return expected lastRefreshTime', () => { expect(actualMetadata.lastRefreshTime).to.equal(new Date(expectedLastRefreshAt).toUTCString()) }); + + it('should return null when lastRefreshTime is not available', () => { + const metadata: UserMetadata = new UserMetadata({ + localId: 'uid123', + lastLoginAt: expectedLastLoginAt.toString(), + createdAt: expectedCreatedAt.toString(), + }); + expect(metadata.lastRefreshTime).to.be.null; + }); }); describe('toJSON', () => {