Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): Properly parse the lastRefreshTime. #888

Merged
merged 4 commits into from May 12, 2020

Conversation

rsgowman
Copy link
Member

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

Fixes #887

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

Fixes #887
@hiranya911 hiranya911 changed the title Properly parse the lastRefreshTime. fix(auth): Properly parse the lastRefreshTime. May 12, 2020
Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. Just a couple of suggestions.

test/integration/auth.spec.ts Outdated Show resolved Hide resolved
test/integration/auth.spec.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM 👍

@@ -336,6 +336,10 @@ describe('admin.auth', () => {
.then((userRecord) => {
expect(userRecord.metadata.lastRefreshTime).to.exist;
expect(isUTCString(userRecord.metadata.lastRefreshTime!));
const creationTime = new Date(userRecord.metadata.creationTime).getTime();
const lastRefreshTime = new Date(userRecord.metadata.lastRefreshTime).getTime();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need ! to satisfy the compiler.

const creationTime = new Date(userRecord.metadata.creationTime).getTime();
const lastRefreshTime = new Date(userRecord.metadata.lastRefreshTime!).getTime();
expect(creationTime).lte(lastRefreshTime);
expect(lastRefreshTime).lte(creationTime + 3600*1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add spaces: 3600 * 1000

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -326,7 +326,8 @@ export class UserMetadata {
// These bugs have already been addressed since then.
utils.addReadonlyGetter(this, 'creationTime', parseDate(response.createdAt));
utils.addReadonlyGetter(this, 'lastSignInTime', parseDate(response.lastLoginAt));
utils.addReadonlyGetter(this, 'lastRefreshTime', parseDate(response.lastRefreshAt));
const lastRefreshAt = response.lastRefreshAt ? new Date(response.lastRefreshAt).toUTCString() : null;
utils.addReadonlyGetter(this, 'lastRefreshTime', lastRefreshAt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to return this in toJSON and add a test for it

return {
  lastSignInTime: this.lastSignInTime,	
  creationTime: this.creationTime,
  lastRefreshTime: this.refreshTime,
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the followup (#889)

@@ -616,10 +616,12 @@ describe('UserInfo', () => {
describe('UserMetadata', () => {
const expectedLastLoginAt = 1476235905000;
const expectedCreatedAt = 1476136676000;
const expectedLastRefreshAt = "2016-10-12T01:31:45.000Z"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use single quotes:
'2016-10-12T01:31:45.000Z'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@rsgowman rsgowman merged commit d985602 into master May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can not get lastRefreshTime
3 participants