@@ -86,6 +86,8 @@ const char* PersistentConnection::kServerDataTag = "t";
86
86
const char * PersistentConnection::kServerDataWarnings = " w" ;
87
87
const char * PersistentConnection::kServerResponseData = " d" ;
88
88
89
+ int PersistentConnection::kInvalidAuthTokenThreshold = 3 ;
90
+
89
91
compat::Atomic<uint32_t > PersistentConnection::next_log_id_ (0 );
90
92
91
93
// Util function to print QuerySpec in debug logs.
@@ -108,6 +110,7 @@ PersistentConnection::PersistentConnection(
108
110
realtime_(nullptr ),
109
111
connection_state_(kDisconnected ),
110
112
is_first_connection_(true ),
113
+ invalid_auth_token_count(0 ),
111
114
next_request_id_(0 ),
112
115
force_auth_refresh_(false ),
113
116
next_listen_id_(0 ),
@@ -926,6 +929,7 @@ void PersistentConnection::HandleAuthTokenResponse(const Variant& message,
926
929
std::string status = GetStringValue (message, kRequestStatus );
927
930
928
931
if (status == kRequestStatusOk ) {
932
+ invalid_auth_token_count = 0 ;
929
933
event_handler_->OnAuthStatus (true );
930
934
LogDebug (" %s Authentication success" , log_id_.c_str ());
931
935
@@ -944,8 +948,25 @@ void PersistentConnection::HandleAuthTokenResponse(const Variant& message,
944
948
status.c_str (), reason.c_str ());
945
949
realtime_->Close ();
946
950
947
- // TODO(chkuang): schedule another time to retrieve and send another auth
948
- // token
951
+ Error error = StatusStringToErrorCode (status);
952
+ if (error == kErrorInvalidToken ) {
953
+ // We'll wait a couple times before logging the warning / increasing the
954
+ // retry period since oauth tokens will report as "invalid" if they're
955
+ // just expired. Plus there may be transient issues that resolve
956
+ // themselves.
957
+ ++invalid_auth_token_count;
958
+
959
+ if (invalid_auth_token_count >= kInvalidAuthTokenThreshold ) {
960
+ // TODO(chkuang): Maximize retry interval (after retry is properly
961
+ // implemented).
962
+ LogWarning (
963
+ " Provided authentication credentials are invalid. This indicates "
964
+ " your FirebaseApp instance was not initialized correctly. Make "
965
+ " sure your google-services.json file has the correct firebase_url "
966
+ " and api_key. You can re-download google-services.json from "
967
+ " https://console.firebase.google.com/." );
968
+ }
969
+ }
949
970
}
950
971
}
951
972
0 commit comments