Skip to content

Can not get lastRefreshTime #887

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

Closed
fpeterdev opened this issue May 12, 2020 · 4 comments · Fixed by #888
Closed

Can not get lastRefreshTime #887

fpeterdev opened this issue May 12, 2020 · 4 comments · Fixed by #888

Comments

@fpeterdev
Copy link

[READ] Step 1: Are you in the right place?

yes

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Windows 10 Home Version 1903
  • Firebase SDK version: 8.12.1
  • Firebase Product: auth
  • Node.js version: 8.15.0
  • NPM version: 6.4.1

[REQUIRED] Step 3: Describe the problem

I can't retrieve the lastRefreshTime for any user. Tried for several users, both in the emulator and on the server, always with the same result.

Relevant Code:

const uid = 'myUserId';
const myUser = await admin.auth().getUser(uid);
console.log(JSON.stringify(myUser.metadata, null, 2));
console.log(JSON.stringify(myUser.metadata.lastRefreshTime));

The code above always writes the following to the console output respectively:

// first console.log()
{
  "lastSignInTime": "Tue, 12 May 2020 07:41:34 GMT",
  "creationTime": "Fri, 04 Jan 2019 09:18:21 GMT"
}
//second console.log()
"Thu, 01 Jan 1970 00:00:02 GMT"
@bojeil-google
Copy link
Contributor

Seems like a bug.
I noticed we are using parseDate to parse this when it is using the .toISOString() format:

"lastRefreshAt": "2020-05-12T08:11:19.863Z"

When we should be handling it like enrolledAt

@hiranya911
Copy link
Contributor

hiranya911 commented May 12, 2020

I think this is because of the way UserMetata.toJson() is implemented:

public toJSON(): object {
    return {
      lastSignInTime: this.lastSignInTime,
      creationTime: this.creationTime,
    };
  }

lastRefreshTime currently only has a getter.

rsgowman added a commit that referenced this issue May 12, 2020
It's returned from the server in a different format than the other timestamps.

Fixes #887
@rsgowman
Copy link
Member

You're both right; there's two bugs here. One with the way the time is parsed (lastRefreshAt is returned from the server differently then the other timestamps) and the other bug (or at least omission) is that the toJSON method doesn't report the lastRefreshTime.

Actually, there's a third bug too: importing users does not record the lastRefreshTime. (Noticed that while looking at this bug.) The other two probably only apply to the node port, but this one likely applies to all 5.

The incorrect parsing of lastRefreshedAt bugs me; I knew the time was returned by the backend differently, and I've even handled that correctly in the other ports (though will definitely need to go back and verify that now that I know I've missed this at least once). Unfortunately, javascript's Date constructor is too permissive, as were our tests. Had either been a little tighter, this would've been caught much earlier. I've adjusted the tests to require a tighter bound on the resulting timestamp.

rsgowman added a commit that referenced this issue May 12, 2020
It's returned from the server in a different format than the other timestamps.

Fixes #887
@fpeterdev
Copy link
Author

Thank you for the quick response and fix. Really appreciate it!

lahirumaramba pushed a commit that referenced this issue Jun 23, 2022
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants