Skip to content

Commit 85d6801

Browse files
authored
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
1 parent c832407 commit 85d6801

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,10 @@ public static WritableMap getExceptionMap(Exception exception) {
9797
}
9898

9999
public static String timestampToUTC(long timestamp) {
100-
Calendar calendar = Calendar.getInstance();
101100
long millisTimestamp = timestamp * 1000;
102-
Date date = new Date(millisTimestamp + calendar.getTimeZone().getOffset(millisTimestamp));
103-
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
101+
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
104102
format.setTimeZone(TimeZone.getTimeZone("UTC"));
105-
return format.format(date);
103+
return format.format(millisTimestamp);
106104
}
107105

108106
/**

packages/auth/e2e/user.e2e.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ describe('auth().currentUser', function () {
7171

7272
tokenResult.claims.should.be.a.Object();
7373
tokenResult.claims.iat.should.be.a.Number();
74+
tokenResult.claims.exp.should.be.a.Number();
7475
tokenResult.claims.iss.should.be.a.String();
7576

77+
new Date(tokenResult.issuedAtTime).getTime().should.equal(tokenResult.claims.iat * 1000);
78+
new Date(tokenResult.expirationTime).getTime().should.equal(tokenResult.claims.exp * 1000);
79+
7680
tokenResult.signInProvider.should.equal('password');
7781
tokenResult.token.length.should.be.greaterThan(24);
7882

0 commit comments

Comments
 (0)