flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [firebase_auth] user.metdata.creationTime wrong milliseconds

Open deepak786 opened this issue 1 year ago • 1 comments

Bug report

Describe the bug The milliseconds since the epoch returned by the creationTime is according to the local time zone. But it should be according to the UTC time zone as the Firebase user has the timestamp in UTC.

Steps to reproduce

Here is the metadata of the Firebase user from the Firebase Admin API https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data

metadata: {
    lastSignInTime: 'Tue, 19 Jul 2022 19:09:20 GMT',
    creationTime: 'Tue, 12 Sep 2017 22:57:06 GMT'
}

As you can see that the creationTime is in UTC. Parsing the creationTime in JS:

console.log(Date.parse(userRecord.metadata.creationTime)); // output: 1505257026000

Screen Shot 2022-07-20 at 2 22 05 PM

When I get the creationTime in Flutter app:

print(user?.metadata.creationTime?.millisecondsSinceEpoch); // output: 1505237226000

Screen Shot 2022-07-20 at 2 23 08 PM

Expected behavior

creationTime should be the same as returned by the Firebase Admin.

deepak786 avatar Jul 20 '22 09:07 deepak786

I have tested in the native Android using Firebase auth SDK.

System.out.println(user.getMetadata().getCreationTimestamp()); // output 1505257026000

The creationTime returned by the Firebase auth Android SDK is the same as that returned by the Firebase Admin.

In the Flutter, the issue is because the _creationTimestamp is parsed in local timezone. see https://github.com/firebase/flutterfire/blob/53138264063105158ee008ea74cbf0ef068473a6/packages/firebase_auth/firebase_auth_platform_interface/lib/src/user_metadata.dart#L20

It should be

DateTime.fromMillisecondsSinceEpoch(_creationTimestamp!, isUtc: true);

OR just return the _creationTimestamp because we know that timestamp from Firebase is in UTC.

deepak786 avatar Jul 20 '22 09:07 deepak786