@@ -86,6 +86,8 @@ const char* PersistentConnection::kServerDataTag = "t";
8686const char * PersistentConnection::kServerDataWarnings = " w" ;
8787const char * PersistentConnection::kServerResponseData = " d" ;
8888
89+ int PersistentConnection::kInvalidAuthTokenThreshold = 3 ;
90+
8991compat::Atomic<uint32_t > PersistentConnection::next_log_id_ (0 );
9092
9193// Util function to print QuerySpec in debug logs.
@@ -108,6 +110,7 @@ PersistentConnection::PersistentConnection(
108110 realtime_(nullptr ),
109111 connection_state_(kDisconnected ),
110112 is_first_connection_(true ),
113+ invalid_auth_token_count(0 ),
111114 next_request_id_(0 ),
112115 force_auth_refresh_(false ),
113116 next_listen_id_(0 ),
@@ -926,6 +929,7 @@ void PersistentConnection::HandleAuthTokenResponse(const Variant& message,
926929 std::string status = GetStringValue (message, kRequestStatus );
927930
928931 if (status == kRequestStatusOk ) {
932+ invalid_auth_token_count = 0 ;
929933 event_handler_->OnAuthStatus (true );
930934 LogDebug (" %s Authentication success" , log_id_.c_str ());
931935
@@ -944,8 +948,25 @@ void PersistentConnection::HandleAuthTokenResponse(const Variant& message,
944948 status.c_str (), reason.c_str ());
945949 realtime_->Close ();
946950
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+ }
949970 }
950971}
951972
0 commit comments