Skip to content

Commit efe94a6

Browse files
committed
add FirebaseUser reload() method
1 parent da705de commit efe94a6

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

firebase-auth-rest/core/src/main/java/com/anotherdev/firebase/auth/FirebaseUser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public interface FirebaseUser {
4141
@NonNull
4242
Single<SignInResponse> reauthenticate(@NonNull AuthCredential credential);
4343

44+
@NonNull
45+
Completable reload();
46+
4447
@NonNull
4548
Completable updateProfile(@NonNull UserProfileChangeRequest request);
4649

firebase-auth-rest/core/src/main/java/com/anotherdev/firebase/auth/data/model/FirebaseUserImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,19 @@ public Single<SignInResponse> reauthenticate(@NonNull AuthCredential credential)
190190
}
191191
}
192192

193+
@NonNull
194+
@Override
195+
public Completable reload() {
196+
return Completable.fromAction(() -> {
197+
if (idToken != null) {
198+
getAuthInternal().getAccountInfo(idToken);
199+
} else {
200+
String error = String.format("idToken is null. Cannot reload user: %s", getUid());
201+
throw new IllegalStateException(error);
202+
}
203+
});
204+
}
205+
193206
@NonNull
194207
@Override
195208
public Completable updateProfile(@NonNull UserProfileChangeRequest request) {

firebase-auth-rest/core/src/main/java/com/anotherdev/firebase/auth/rest/RestAuthProvider.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,22 @@ private void saveCurrentUser(String idToken, String refreshToken) throws Firebas
255255
}
256256

257257
private SignInResponse getAccountInfo(SignInResponse signInResponse) {
258+
getAccountInfo(signInResponse.getIdToken());
259+
return signInResponse;
260+
}
261+
262+
public void getAccountInfo(@NonNull String idToken) {
258263
GetAccountInfoRequest request = GetAccountInfoRequest.builder()
259-
.idToken(signInResponse.getIdToken())
264+
.idToken(idToken)
260265
.build();
261266
GetAccountInfoResponse accountInfo = RestAuthApi.auth()
262-
.getAccounts(request).blockingGet();
267+
.getAccounts(request)
268+
.blockingGet();
263269

264270
Data dataStore = Data.from(app.getApplicationContext());
265271
for (UserProfile profile : accountInfo.getUsers()) {
266272
final String uid = profile.getLocalId();
267273
dataStore.getUserProfile(uid).set(profile);
268274
}
269-
return signInResponse;
270275
}
271276
}

0 commit comments

Comments
 (0)