Skip to content

Commit e46b62d

Browse files
Refetch token if attempt was invalidated
1 parent 3da23a6 commit e46b62d

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

firebase-firestore/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Unreleased
2+
- [fixed] Fixed an issue that may have prevented the client from connecting
3+
to the backend directly after a user signed in.
24

35
# 21.4.3
46
- [changed] Firestore now limits the number of concurrent document lookups it

firebase-firestore/src/main/java/com/google/firebase/firestore/auth/FirebaseAuthCredentialsProvider.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
import androidx.annotation.NonNull;
1818
import androidx.annotation.Nullable;
1919
import com.google.android.gms.tasks.Task;
20+
import com.google.android.gms.tasks.Tasks;
2021
import com.google.firebase.FirebaseApp;
2122
import com.google.firebase.auth.GetTokenResult;
2223
import com.google.firebase.auth.internal.IdTokenListener;
2324
import com.google.firebase.auth.internal.InternalAuthProvider;
24-
import com.google.firebase.firestore.FirebaseFirestoreException;
25-
import com.google.firebase.firestore.FirebaseFirestoreException.Code;
25+
import com.google.firebase.firestore.util.Executors;
2626
import com.google.firebase.firestore.util.Listener;
27+
import com.google.firebase.firestore.util.Logger;
2728

2829
/**
2930
* FirebaseAuthCredentialsProvider uses Firebase Auth via {@link FirebaseApp} to get an auth token.
@@ -37,6 +38,8 @@
3738
*/
3839
public final class FirebaseAuthCredentialsProvider extends CredentialsProvider {
3940

41+
private static final String LOG_TAG = "FirebaseAuthCredentialsProvider";
42+
4043
private final InternalAuthProvider authProvider;
4144

4245
/**
@@ -85,19 +88,21 @@ public synchronized Task<String> getToken() {
8588
// Take note of the current value of the tokenCounter so that this method can fail (with a
8689
// FirebaseFirestoreException) if there is a token change while the request is outstanding.
8790
final int savedCounter = tokenCounter;
88-
return res.continueWith(
91+
return res.continueWithTask(
92+
Executors.DIRECT_EXECUTOR,
8993
task -> {
9094
synchronized (this) {
9195
// Cancel the request since the token changed while the request was outstanding so the
9296
// response is potentially for a previous user (which user, we can't be sure).
9397
if (savedCounter != tokenCounter) {
94-
throw new FirebaseFirestoreException(
95-
"getToken aborted due to token change", Code.ABORTED);
98+
Logger.debug(LOG_TAG, "getToken aborted due to token change");
99+
return getToken();
96100
}
97-
if (!task.isSuccessful()) {
98-
throw task.getException();
101+
102+
if (task.isSuccessful()) {
103+
return Tasks.forResult(task.getResult().getToken());
99104
} else {
100-
return task.getResult().getToken();
105+
return Tasks.forException(task.getException());
101106
}
102107
}
103108
});

0 commit comments

Comments
 (0)