Skip to content

Commit cfea847

Browse files
authored
Add lastRefreshTime to UserMetadata toJSON method. (#889)
* 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.
1 parent c13aab5 commit cfea847

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/auth/user-record.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export class UserMetadata {
337337
return {
338338
lastSignInTime: this.lastSignInTime,
339339
creationTime: this.creationTime,
340+
lastRefreshTime: this.lastRefreshTime,
340341
};
341342
}
342343
}

test/integration/auth.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { deepExtend, deepCopy } from '../../src/utils/deep-copy';
3131
import {
3232
AuthProviderConfig, CreateTenantRequest, DeleteUsersResult, PhoneMultiFactorInfo,
3333
TenantAwareAuth, UpdatePhoneMultiFactorInfoRequest, UpdateTenantRequest, UserImportOptions,
34-
UserImportRecord, UserRecord, getAuth,
34+
UserImportRecord, UserMetadata, UserRecord, getAuth,
3535
} from '../../lib/auth/index';
3636

3737
const chalk = require('chalk'); // eslint-disable-line @typescript-eslint/no-var-requires
@@ -2517,6 +2517,8 @@ describe('admin.auth', () => {
25172517
metadata: {
25182518
lastSignInTime: now,
25192519
creationTime: now,
2520+
// TODO(rsgowman): Enable once importing users supports lastRefreshTime
2521+
//lastRefreshTime: now,
25202522
},
25212523
providerData: [
25222524
{
@@ -2548,6 +2550,11 @@ describe('admin.auth', () => {
25482550
providerId: 'phone',
25492551
phoneNumber: importUserRecord.phoneNumber!,
25502552
});
2553+
// The lastRefreshTime should be set to null
2554+
type Writable<UserMetadata> = {
2555+
-readonly [k in keyof UserMetadata]: UserMetadata[k];
2556+
};
2557+
(importUserRecord.metadata as Writable<UserMetadata>).lastRefreshTime = null;
25512558
const actualUserRecord: {[key: string]: any} = userRecord.toJSON();
25522559
for (const key of Object.keys(importUserRecord)) {
25532560
expect(JSON.stringify(actualUserRecord[key]))

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ function getValidUserResponse(tenantId?: string): GetAccountInfoUserResponse {
8383
validSince: '1476136676',
8484
lastLoginAt: '1476235905000',
8585
createdAt: '1476136676000',
86+
lastRefreshAt: '2016-10-12T01:31:45.000Z',
8687
customAttributes: JSON.stringify({
8788
admin: true,
8889
}),
@@ -159,6 +160,7 @@ function getUserJSON(tenantId?: string): object {
159160
metadata: {
160161
lastSignInTime: new Date(1476235905000).toUTCString(),
161162
creationTime: new Date(1476136676000).toUTCString(),
163+
lastRefreshTime: new Date(1476235905000).toUTCString(),
162164
},
163165
customClaims: {
164166
admin: true,
@@ -629,6 +631,7 @@ describe('UserMetadata', () => {
629631
const expectedMetadataJSON = {
630632
lastSignInTime: new Date(expectedLastLoginAt).toUTCString(),
631633
creationTime: new Date(expectedCreatedAt).toUTCString(),
634+
lastRefreshTime: new Date(expectedLastRefreshAt).toUTCString(),
632635
};
633636

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

0 commit comments

Comments
 (0)