Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/auth/user-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export interface GetAccountInfoUserResponse {
createdAt?: string;
lastLoginAt?: string;
lastRefreshAt?: string;
passwordUpdatedAt?: number | string;
[key: string]: any;
}

Expand Down Expand Up @@ -379,6 +380,12 @@ export class UserMetadata {
*/
public readonly lastRefreshTime?: string | null;

/**
* The date the user's password was last updated, formatted as a UTC string.
* Returns null if the user has never updated their password.
*/
public readonly passwordUpdatedAt?: string | null;

/**
* @param response - The server side response returned from the `getAccountInfo`
* endpoint.
Expand All @@ -394,6 +401,7 @@ export class UserMetadata {
utils.addReadonlyGetter(this, 'lastSignInTime', parseDate(response.lastLoginAt));
const lastRefreshAt = response.lastRefreshAt ? new Date(response.lastRefreshAt).toUTCString() : null;
utils.addReadonlyGetter(this, 'lastRefreshTime', lastRefreshAt);
utils.addReadonlyGetter(this, 'passwordUpdatedAt', parseDate(response.passwordUpdatedAt));
}

/**
Expand All @@ -406,6 +414,7 @@ export class UserMetadata {
lastSignInTime: this.lastSignInTime,
creationTime: this.creationTime,
lastRefreshTime: this.lastRefreshTime,
passwordUpdatedAt: this.passwordUpdatedAt,
};
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/unit/auth/user-record.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function getValidUserResponse(tenantId?: string): GetAccountInfoUserResponse {
photoUrl: 'https://lh3.googleusercontent.com/1234567890/photo.jpg',
validSince: '1476136676',
lastLoginAt: '1476235905000',
passwordUpdatedAt: '1476235905000',
createdAt: '1476136676000',
lastRefreshAt: '2016-10-12T01:31:45.000Z',
customAttributes: JSON.stringify({
Expand Down Expand Up @@ -161,6 +162,7 @@ function getUserJSON(tenantId?: string): object {
lastSignInTime: new Date(1476235905000).toUTCString(),
creationTime: new Date(1476136676000).toUTCString(),
lastRefreshTime: new Date(1476235905000).toUTCString(),
passwordUpdatedAt: new Date(1476235905000).toUTCString(),
},
customClaims: {
admin: true,
Expand Down Expand Up @@ -775,16 +777,19 @@ describe('UserMetadata', () => {
const expectedLastLoginAt = 1476235905000;
const expectedCreatedAt = 1476136676000;
const expectedLastRefreshAt = '2016-10-12T01:31:45.000Z';
const expectedPasswordUpdatedAt = 1476235905000;
const actualMetadata: UserMetadata = new UserMetadata({
localId: 'uid123',
lastLoginAt: expectedLastLoginAt.toString(),
createdAt: expectedCreatedAt.toString(),
lastRefreshAt: expectedLastRefreshAt,
passwordUpdatedAt: expectedPasswordUpdatedAt,
});
const expectedMetadataJSON = {
lastSignInTime: new Date(expectedLastLoginAt).toUTCString(),
creationTime: new Date(expectedCreatedAt).toUTCString(),
lastRefreshTime: new Date(expectedLastRefreshAt).toUTCString(),
passwordUpdatedAt: new Date(expectedPasswordUpdatedAt).toUTCString(),
};

describe('constructor', () => {
Expand Down Expand Up @@ -850,6 +855,20 @@ describe('UserMetadata', () => {
});
expect(metadata.lastRefreshTime).to.be.null;
});

it('should return expected passwordUpdatedAt', () => {
expect(actualMetadata.passwordUpdatedAt).to.equal(
new Date(expectedPasswordUpdatedAt).toUTCString());
});

it('should return null when passwordUpdatedAt is not available', () => {
const metadata: UserMetadata = new UserMetadata({
localId: 'uid123',
lastLoginAt: expectedLastLoginAt.toString(),
createdAt: expectedCreatedAt.toString(),
});
expect(metadata.passwordUpdatedAt).to.be.null;
});
});

describe('toJSON', () => {
Expand Down Expand Up @@ -1047,6 +1066,7 @@ describe('UserRecord', () => {
createdAt: '1476136676000',
lastLoginAt: '1476235905000',
lastRefreshAt: '2016-10-12T01:31:45.000Z',
passwordUpdatedAt: '1476235905000',
} as any);
expect(userRecord.metadata).to.deep.equal(metadata);
});
Expand Down