Skip to content

Commit

Permalink
Add lastRefreshTime to UserMetadata toJSON method. (#889)
Browse files Browse the repository at this point in the history
* Properly parse the lastRefreshTime.

It's returned from the server in a different format than the other timestamps.

Fixes #887

* Add lastRefreshTime to UserMetadata toJSON method.

See #887

* Don't specify lastRefreshTime in integration tests

Since specifying this when importing users isn't supported.
  • Loading branch information
rsgowman committed Jun 23, 2022
1 parent c13aab5 commit cfea847
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/auth/user-record.ts
Expand Up @@ -337,6 +337,7 @@ export class UserMetadata {
return {
lastSignInTime: this.lastSignInTime,
creationTime: this.creationTime,
lastRefreshTime: this.lastRefreshTime,
};
}
}
Expand Down
9 changes: 8 additions & 1 deletion test/integration/auth.spec.ts
Expand Up @@ -31,7 +31,7 @@ import { deepExtend, deepCopy } from '../../src/utils/deep-copy';
import {
AuthProviderConfig, CreateTenantRequest, DeleteUsersResult, PhoneMultiFactorInfo,
TenantAwareAuth, UpdatePhoneMultiFactorInfoRequest, UpdateTenantRequest, UserImportOptions,
UserImportRecord, UserRecord, getAuth,
UserImportRecord, UserMetadata, UserRecord, getAuth,
} from '../../lib/auth/index';

const chalk = require('chalk'); // eslint-disable-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -2517,6 +2517,8 @@ describe('admin.auth', () => {
metadata: {
lastSignInTime: now,
creationTime: now,
// TODO(rsgowman): Enable once importing users supports lastRefreshTime
//lastRefreshTime: now,
},
providerData: [
{
Expand Down Expand Up @@ -2548,6 +2550,11 @@ describe('admin.auth', () => {
providerId: 'phone',
phoneNumber: importUserRecord.phoneNumber!,
});
// The lastRefreshTime should be set to null
type Writable<UserMetadata> = {
-readonly [k in keyof UserMetadata]: UserMetadata[k];
};
(importUserRecord.metadata as Writable<UserMetadata>).lastRefreshTime = null;
const actualUserRecord: {[key: string]: any} = userRecord.toJSON();
for (const key of Object.keys(importUserRecord)) {
expect(JSON.stringify(actualUserRecord[key]))
Expand Down
4 changes: 4 additions & 0 deletions test/unit/auth/user-record.spec.ts
Expand Up @@ -83,6 +83,7 @@ function getValidUserResponse(tenantId?: string): GetAccountInfoUserResponse {
validSince: '1476136676',
lastLoginAt: '1476235905000',
createdAt: '1476136676000',
lastRefreshAt: '2016-10-12T01:31:45.000Z',
customAttributes: JSON.stringify({
admin: true,
}),
Expand Down Expand Up @@ -159,6 +160,7 @@ function getUserJSON(tenantId?: string): object {
metadata: {
lastSignInTime: new Date(1476235905000).toUTCString(),
creationTime: new Date(1476136676000).toUTCString(),
lastRefreshTime: new Date(1476235905000).toUTCString(),
},
customClaims: {
admin: true,
Expand Down Expand Up @@ -629,6 +631,7 @@ describe('UserMetadata', () => {
const expectedMetadataJSON = {
lastSignInTime: new Date(expectedLastLoginAt).toUTCString(),
creationTime: new Date(expectedCreatedAt).toUTCString(),
lastRefreshTime: new Date(expectedLastRefreshAt).toUTCString(),
};

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

0 comments on commit cfea847

Please sign in to comment.