From 85d6801ecbe9b3922225c55ca3628675ad848764 Mon Sep 17 00:00:00 2001 From: yasu Date: Wed, 10 Feb 2021 01:30:44 +0900 Subject: [PATCH] fix(auth, android): do not timezone offset when getting UTC timestamp (#4886) * Add test for expirationTime of tokenResult * Fix android timestampToUTC util * Use single quote --- .../java/io/invertase/firebase/common/SharedUtils.java | 6 ++---- packages/auth/e2e/user.e2e.js | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java b/packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java index 1eb241c569..b7859adc41 100644 --- a/packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java +++ b/packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java @@ -97,12 +97,10 @@ public static WritableMap getExceptionMap(Exception exception) { } public static String timestampToUTC(long timestamp) { - Calendar calendar = Calendar.getInstance(); long millisTimestamp = timestamp * 1000; - Date date = new Date(millisTimestamp + calendar.getTimeZone().getOffset(millisTimestamp)); - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); format.setTimeZone(TimeZone.getTimeZone("UTC")); - return format.format(date); + return format.format(millisTimestamp); } /** diff --git a/packages/auth/e2e/user.e2e.js b/packages/auth/e2e/user.e2e.js index 8b7917bdde..9e1bcdcace 100644 --- a/packages/auth/e2e/user.e2e.js +++ b/packages/auth/e2e/user.e2e.js @@ -71,8 +71,12 @@ describe('auth().currentUser', function () { tokenResult.claims.should.be.a.Object(); tokenResult.claims.iat.should.be.a.Number(); + tokenResult.claims.exp.should.be.a.Number(); tokenResult.claims.iss.should.be.a.String(); + new Date(tokenResult.issuedAtTime).getTime().should.equal(tokenResult.claims.iat * 1000); + new Date(tokenResult.expirationTime).getTime().should.equal(tokenResult.claims.exp * 1000); + tokenResult.signInProvider.should.equal('password'); tokenResult.token.length.should.be.greaterThan(24);