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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/auth/user-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}

/** @return The plain object representation of the user's metadata. */
Expand Down
6 changes: 6 additions & 0 deletions test/integration/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ describe('admin.auth', () => {
.then((userRecord) => {
expect(userRecord.metadata.lastRefreshTime).to.exist;
expect(isUTCString(userRecord.metadata.lastRefreshTime!));
expect(new Date(userRecord.metadata.creationTime).getTime())
hiranya911 marked this conversation as resolved.
Show resolved Hide resolved
.lte(new Date(userRecord.metadata.lastRefreshTime!).getTime());
const creationTimePlus1Hour = new Date(userRecord.metadata.creationTime);
creationTimePlus1Hour.setHours(creationTimePlus1Hour.getHours()+1);
expect(new Date(userRecord.metadata.lastRefreshTime!).getTime())
.lte(creationTimePlus1Hour.getTime());
hiranya911 marked this conversation as resolved.
Show resolved Hide resolved
});
} finally {
admin.auth().deleteUser('lastRefreshTimeUser');
Expand Down