Skip to content

Commit d985602

Browse files
authored
fix(auth): Properly parse the lastRefreshTime. (#888)
It's returned from the server in a different format than the other timestamps. Fixes #887
1 parent 090adb9 commit d985602

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/auth/user-record.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ export class UserMetadata {
326326
// These bugs have already been addressed since then.
327327
utils.addReadonlyGetter(this, 'creationTime', parseDate(response.createdAt));
328328
utils.addReadonlyGetter(this, 'lastSignInTime', parseDate(response.lastLoginAt));
329-
utils.addReadonlyGetter(this, 'lastRefreshTime', parseDate(response.lastRefreshAt));
329+
const lastRefreshAt = response.lastRefreshAt ? new Date(response.lastRefreshAt).toUTCString() : null;
330+
utils.addReadonlyGetter(this, 'lastRefreshTime', lastRefreshAt);
330331
}
331332

332333
/** @return The plain object representation of the user's metadata. */

test/integration/auth.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ describe('admin.auth', () => {
336336
.then((userRecord) => {
337337
expect(userRecord.metadata.lastRefreshTime).to.exist;
338338
expect(isUTCString(userRecord.metadata.lastRefreshTime!));
339+
const creationTime = new Date(userRecord.metadata.creationTime).getTime();
340+
const lastRefreshTime = new Date(userRecord.metadata.lastRefreshTime!).getTime();
341+
expect(creationTime).lte(lastRefreshTime);
342+
expect(lastRefreshTime).lte(creationTime + 3600 * 1000);
339343
});
340344
} finally {
341345
admin.auth().deleteUser('lastRefreshTimeUser');

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,12 @@ describe('UserInfo', () => {
616616
describe('UserMetadata', () => {
617617
const expectedLastLoginAt = 1476235905000;
618618
const expectedCreatedAt = 1476136676000;
619+
const expectedLastRefreshAt = '2016-10-12T01:31:45.000Z';
619620
const actualMetadata: UserMetadata = new UserMetadata({
620621
localId: 'uid123',
621622
lastLoginAt: expectedLastLoginAt.toString(),
622623
createdAt: expectedCreatedAt.toString(),
624+
lastRefreshAt: expectedLastRefreshAt,
623625
});
624626
const expectedMetadataJSON = {
625627
lastSignInTime: new Date(expectedLastLoginAt).toUTCString(),
@@ -676,6 +678,10 @@ describe('UserMetadata', () => {
676678
(actualMetadata as any).creationTime = new Date();
677679
}).to.throw(Error);
678680
});
681+
682+
it('should return expected lastRefreshTime', () => {
683+
expect(actualMetadata.lastRefreshTime).to.equal(new Date(expectedLastRefreshAt).toUTCString())
684+
});
679685
});
680686

681687
describe('toJSON', () => {

0 commit comments

Comments
 (0)