Skip to content
Prev Previous commit
Next Next commit
reduce lint warning
  • Loading branch information
Cynthia Jiang committed Jul 21, 2023
commit 64fd592446d96fce7e9ca337b79cfa7f1918f2d7
14 changes: 8 additions & 6 deletions auth/src/desktop/auth_desktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
namespace firebase {
namespace auth {

static std::string g_emulator_host;
static uint32_t g_emulator_port;
namespace {

template <typename ResultT>
Expand Down Expand Up @@ -647,15 +645,19 @@ void Auth::SignOut() {
}

void Auth::UseEmulator(const std::string host, uint32_t port) {
g_emulator_host = host;
g_emulator_port = port;
if (!auth_data_) return;
auto auth_impl = static_cast<AuthImpl*>(auth_data_->auth_impl);
auth_impl->emulator_host = host;
auth_impl->emulator_port = port;
}

std::string Auth::GetEmulatorUrl() {
if (g_emulator_host.empty()) {
if (!auth_data_) return "";
auto auth_impl = static_cast<AuthImpl*>(auth_data_->auth_impl);
if (auth_impl->emulator_host.empty()) {
return "";
}
return g_emulator_host + ":" + std::to_string(g_emulator_port) + "/";
return auth_impl->emulator_host + ":" + std::to_string(auth_impl->emulator_port) + "/";
}

// AuthStateListener to wait for current_user_DEPRECATED() until persistent
Expand Down
3 changes: 3 additions & 0 deletions auth/src/desktop/auth_desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ struct AuthImpl {
// The current user language code. This can be set to the app’s current
// language by calling SetLanguageCode.
std::string language_code;

std::string emulator_host;
int32_t emulator_port;
};

// Constant, describing how often we automatically fetch a new auth token.
Expand Down
5 changes: 4 additions & 1 deletion auth/src/desktop/rpcs/auth_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ AuthRequest::AuthRequest(::firebase::App& app, const char* schema,
}
}
}

// Get emulator url
Auth* auth = Auth::GetAuth(&app);
emulator_url = auth->GetEmulatorUrl();
}

std::string AuthRequest::GetUrl() {
std::string emulator_url = ::firebase::auth::Auth::GetEmulatorUrl();
if (emulator_url.empty()) {
std::string url(kHttps);
url += kServerURL;
Expand Down
6 changes: 5 additions & 1 deletion auth/src/desktop/rpcs/auth_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef FIREBASE_AUTH_SRC_DESKTOP_RPCS_AUTH_REQUEST_H_
#define FIREBASE_AUTH_SRC_DESKTOP_RPCS_AUTH_REQUEST_H_

#include <string>

#include "app/rest/request_json.h"
#include "app/src/include/firebase/app.h"
#include "auth/request_generated.h"
Expand All @@ -36,7 +38,7 @@ const char* const kServerURL = "www.googleapis.com/identitytoolkit/v3/relyingpar

class AuthRequest
: public firebase::rest::RequestJson<fbs::Request, fbs::RequestT> {
public:
public:
// App is a non-const parameter because this constructor might modify App's
// internal HeartbeatController by logging or fetching heartbeats.
AuthRequest(::firebase::App& app, const char* schema, bool deliver_heartbeat);
Expand All @@ -47,6 +49,8 @@ class AuthRequest
deliver_heartbeat) {}

std::string GetUrl();
private:
std::string emulator_url;
};

} // namespace auth
Expand Down
3 changes: 2 additions & 1 deletion auth/src/include/firebase/auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define FIREBASE_AUTH_SRC_INCLUDE_FIREBASE_AUTH_H_

#include <vector>
#include <string>

#include "firebase/app.h"
#include "firebase/auth/user.h"
Expand Down Expand Up @@ -637,7 +638,7 @@ class Auth {
void UseEmulator(const std::string host, uint32_t port);

/// Get the emulator url
static std::string GetEmulatorUrl();
std::string GetEmulatorUrl();
#endif // !defined(DOXYGEN)

/// Gets the App this auth object is connected to.
Expand Down