mardi 26 janvier 2021

Why idToken.expirationTime.millisecondsSinceEpoch print difference in flutter web and android?

This took a lot of while for me to figure out. But here is the thing - I am using firebase auth & flutter web -

// sign in with email and password
  Future signInWithEmailAndPassword(String email, String password) async {
    try {
      AuthResult result = await _auth.signInWithEmailAndPassword(
          email: email, password: password);
      FirebaseUser user = result.user;

      final idToken = await user.getIdToken();
      SharedPreferences prefs = await SharedPreferences.getInstance();
      await prefs.setString('firebaseToken', idToken.token);
      await prefs.setInt('firebaseTokenExpirationTime',
          idToken.expirationTime.millisecondsSinceEpoch);
      print(idToken.expirationTime.millisecondsSinceEpoch);
      return user;
    } catch (error) {
      print(error.toString());
      return null;
    }
  }

On android console the print statement output is (in milliseconds)-

Connecting to VM Service at ws://127.0.0.1:55331/dda498rvwU8=/ws
I/flutter (19829): 1611730980000

On chrome (web-javascript) console the print statement output is (in microseconds) -

Connecting to VM Service at ws://127.0.0.1:53442/RYFG8Ym9IEM=/ws
1611730487000000

This is totally messing my refresh logic with getIdToken() because even in web when I print DateTime using this -

print(DateTime.now().millisecondsSinceEpoch);

it shows the following -

on android output is (in milliseconds)-

I/flutter (19829): 1611727629566

on chrome (web-javascript) output is (in milliseconds) -

1611727775216

So it boils down to - why idToken.expirationTime.millisecondsSinceEpoch is showing output in microseconds on flutter web? Is anyone else observing the same?




Aucun commentaire:

Enregistrer un commentaire