Skip to content

Commit ae6659d

Browse files
I will remove the deprecated User::UpdateEmail from the C++ SDK and all tests.
To match a change made in the Unity SDK, I will remove: - Auth: `User::UpdateEmail` and `User::UpdateEmailLastResult` methods. I will also remove all usages of the deprecated method from the integration tests (`auth/integration_test/src/integration_test.cc`) and unit tests (`auth/tests/user_test.cc` and `auth/tests/desktop/user_desktop_test.cc`). I will then update the release notes to reflect this change.
1 parent e8749f5 commit ae6659d

File tree

8 files changed

+79
-82
lines changed

8 files changed

+79
-82
lines changed

auth/src/android/user_android.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ METHOD_LOOKUP_DEFINITION(tokenresult,
4141
X(IsAnonymous, "isAnonymous", "()Z"), \
4242
X(Token, "getIdToken", "(Z)Lcom/google/android/gms/tasks/Task;"), \
4343
X(ProviderData, "getProviderData", "()Ljava/util/List;"), \
44+
X(UpdateEmail, "updateEmail", "(Ljava/lang/String;)" \
45+
"Lcom/google/android/gms/tasks/Task;"), \
4446
X(VerifyBeforeUpdateEmail, "verifyBeforeUpdateEmail", \
4547
"(Ljava/lang/String;)Lcom/google/android/gms/tasks/Task;"), \
4648
X(UpdatePassword, "updatePassword", "(Ljava/lang/String;)" \
@@ -351,6 +353,26 @@ std::vector<UserInfoInterface> User::provider_data() const {
351353
return provider_data;
352354
}
353355

356+
Future<void> User::UpdateEmail(const char* email) {
357+
if (!ValidUser(auth_data_)) {
358+
return Future<void>();
359+
}
360+
ReferenceCountedFutureImpl& futures = auth_data_->future_impl;
361+
const auto handle = futures.SafeAlloc<void>(kUserFn_UpdateEmail);
362+
JNIEnv* env = Env(auth_data_);
363+
364+
jstring j_email = env->NewStringUTF(email);
365+
jobject pending_result = env->CallObjectMethod(
366+
UserImpl(auth_data_), user::GetMethodId(user::kUpdateEmail), j_email);
367+
env->DeleteLocalRef(j_email);
368+
369+
if (!CheckAndCompleteFutureOnError(env, &futures, handle)) {
370+
RegisterCallback(pending_result, handle, auth_data_, nullptr);
371+
env->DeleteLocalRef(pending_result);
372+
}
373+
return MakeFuture(&futures, handle);
374+
}
375+
354376
Future<void> User::UpdatePassword(const char* password) {
355377
if (!ValidUser(auth_data_)) {
356378
return Future<void>();

auth/src/desktop/user_desktop.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,34 @@ Future<void> User::Reload() {
835835
callback);
836836
}
837837

838+
Future<void> User::UpdateEmail(const char* const email) {
839+
if (auth_data_ == nullptr) { // user is not valid
840+
return Future<void>(); // invalid future
841+
}
842+
Promise<void> promise(&auth_data_->future_impl, kUserFn_UpdateEmail);
843+
if (!ValidateCurrentUser(&promise, auth_data_)) {
844+
return promise.LastResult();
845+
}
846+
if (!ValidateEmail(&promise, email)) {
847+
return promise.LastResult();
848+
}
849+
if (!ValidateCurrentUser(&promise, auth_data_)) {
850+
return promise.LastResult();
851+
}
852+
853+
const char* language_code = nullptr;
854+
auto auth_impl = static_cast<AuthImpl*>(auth_data_->auth_impl);
855+
if (!auth_impl->language_code.empty()) {
856+
language_code = auth_impl->language_code.c_str();
857+
}
858+
859+
typedef SetAccountInfoRequest RequestT;
860+
auto request = RequestT::CreateUpdateEmailRequest(
861+
*auth_data_->app, GetApiKey(*auth_data_), email);
862+
return CallAsyncWithFreshToken(auth_data_, promise, std::move(request),
863+
PerformSetAccountInfoFlow<void>);
864+
}
865+
838866
Future<void> User::UpdatePassword(const char* const password) {
839867
if (auth_data_ == nullptr) { // user is not valid
840868
return Future<void>(); // invalid future

auth/src/include/firebase/auth/user.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,20 @@ class User : public UserInfoInterface {
229229
/// </SWIG>
230230
std::vector<UserInfoInterface> provider_data() const;
231231

232+
/// @deprecated This is a deprecated method. Please use
233+
/// SendEmailVerificationBeforeUpdatingEmail(email) instead.
234+
///
235+
/// Sets the email address for the user.
236+
///
237+
/// May fail if there is already an email/password-based account for the same
238+
/// email address.
239+
FIREBASE_DEPRECATED Future<void> UpdateEmail(const char* email);
240+
241+
/// @deprecated
242+
///
243+
/// Get results of the most recent call to UpdateEmail.
244+
FIREBASE_DEPRECATED Future<void> UpdateEmailLastResult() const;
245+
232246
/// Attempts to change the password for the current user.
233247
///
234248
/// For an account linked to an Identity Provider (IDP) with no password,

auth/src/ios/user_ios.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ explicit IOSWrappedUserInfo(id<FIRUserInfo> user_info) : user_info_(user_info) {
102102
return provider_data;
103103
}
104104

105+
Future<void> User::UpdateEmail(const char *email) {
106+
if (!ValidUser(auth_data_)) {
107+
return Future<void>();
108+
}
109+
ReferenceCountedFutureImpl &futures = auth_data_->future_impl;
110+
const auto handle = futures.SafeAlloc<void>(kUserFn_UpdateEmail);
111+
[UserImpl(auth_data_) updateEmail:@(email)
112+
completion:^(NSError *_Nullable error) {
113+
futures.Complete(handle, AuthErrorFromNSError(error),
114+
[error.localizedDescription UTF8String]);
115+
}];
116+
return MakeFuture(&futures, handle);
117+
}
118+
105119
Future<void> User::UpdatePassword(const char *password) {
106120
if (!ValidUser(auth_data_)) {
107121
return Future<void>();

auth/src/user.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace firebase {
2020
namespace auth {
2121

2222
AUTH_RESULT_FN(User, GetToken, std::string)
23+
AUTH_RESULT_FN(User, UpdateEmail, void)
2324
AUTH_RESULT_FN(User, UpdatePassword, void)
2425
AUTH_RESULT_FN(User, LinkWithCredential, AuthResult)
2526
AUTH_RESULT_FN(User, Reauthenticate, void)

auth/tests/desktop/user_desktop_test.cc

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -436,23 +436,6 @@ TEST_F(UserDesktopTest, TestReload) {
436436
VerifyProviderData(firebase_user_);
437437
}
438438

439-
// Tests the happy case of setting a new email on the currently logged in user.
440-
TEST_F(UserDesktopTest, TestUpdateEmail) {
441-
InitializeConfigWithAFake(GetUrlForApi(API_KEY, "setAccountInfo"),
442-
FakeSetAccountInfoResponse());
443-
444-
// SetAccountInfoResponse contains a new token.
445-
id_token_listener.ExpectChanges(1);
446-
auth_state_listener.ExpectChanges(0);
447-
448-
const std::string new_email = "[email protected]";
449-
450-
EXPECT_NE(new_email, firebase_user_.email());
451-
WaitForFuture(firebase_user_.UpdateEmail(new_email.c_str()));
452-
EXPECT_EQ(new_email, firebase_user_.email());
453-
VerifyProviderData(firebase_user_);
454-
}
455-
456439
// Tests the happy case of setting a new password on the currently logged in
457440
// user.
458441
TEST_F(UserDesktopTest, TestUpdatePassword) {
@@ -815,16 +798,6 @@ TEST_F(UserDesktopTestSignOutOnError, Reload) {
815798
sem_.Wait();
816799
}
817800

818-
TEST_F(UserDesktopTestSignOutOnError, UpdateEmail) {
819-
CheckSignOutIfUserIsInvalid(
820-
GetUrlForApi(API_KEY, "setAccountInfo"), "USER_NOT_FOUND",
821-
kAuthErrorUserNotFound, [&] {
822-
sem_.Post();
823-
return firebase_user_.UpdateEmail("[email protected]");
824-
});
825-
sem_.Wait();
826-
}
827-
828801
TEST_F(UserDesktopTestSignOutOnError, UpdatePassword) {
829802
CheckSignOutIfUserIsInvalid(
830803
GetUrlForApi(API_KEY, "setAccountInfo"), "USER_DISABLED",
@@ -881,30 +854,6 @@ TEST_F(UserDesktopTestSignOutOnError, GetToken) {
881854
sem_.Wait();
882855
}
883856

884-
// This test is to expose potential race condition and is primarily intended to
885-
// be run with --config=tsan
886-
TEST_F(UserDesktopTest, TestRaceCondition_SetAccountInfoAndSignOut) {
887-
InitializeConfigWithAFake(GetUrlForApi(API_KEY, "setAccountInfo"),
888-
FakeSetAccountInfoResponse());
889-
890-
// SignOut is engaged on the main thread, whereas UpdateEmail will be executed
891-
// on the background thread; consequently, the order in which they are
892-
// executed is not defined. Nevertheless, this should not lead to any data
893-
// corruption, when UpdateEmail writes to user profile while it's being
894-
// deleted by SignOut. Whichever method succeeds first, user must be signed
895-
// out once both are finished: if SignOut finishes last, it overrides the
896-
// updated user, and if UpdateEmail finishes last, it should note that there
897-
// is no currently signed in user and fail with kAuthErrorUserNotFound.
898-
899-
auto future = firebase_user_.UpdateEmail("some_email");
900-
firebase_auth_->SignOut();
901-
while (future.status() == firebase::kFutureStatusPending) {
902-
}
903-
904-
EXPECT_THAT(future.error(), AnyOf(kAuthErrorNone, kAuthErrorNoSignedInUser));
905-
EXPECT_FALSE(firebase_auth_->current_user().is_valid());
906-
}
907-
908857
// LinkWithProvider tests.
909858
TEST_F(UserDesktopTest, TestLinkWithProviderReturnsUnsupportedError) {
910859
FederatedOAuthProvider provider;

auth/tests/user_test.cc

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -258,36 +258,6 @@ TEST_F(UserTest, TestGetProviderData) {
258258
EXPECT_TRUE(provider.empty());
259259
}
260260

261-
TEST_F(UserTest, TestUpdateEmail) {
262-
const std::string config =
263-
std::string(
264-
"{"
265-
" config:["
266-
" {fake:'FirebaseUser.updateEmail', futuregeneric:{ticker:1}},"
267-
" {fake:'FIRUser.updateEmail:completion:', futuregeneric:"
268-
"{ticker:1}},") +
269-
SET_ACCOUNT_INFO_SUCCESSFUL_RESPONSE +
270-
" ]"
271-
"}";
272-
firebase::testing::cppsdk::ConfigSet(config.c_str());
273-
274-
EXPECT_NE("[email protected]", firebase_user_.email());
275-
Future<void> result = firebase_user_.UpdateEmail("[email protected]");
276-
277-
// Fake Android & iOS implemented the delay. Desktop stub completed immediately.
278-
#if defined(FIREBASE_ANDROID_FOR_DESKTOP) || FIREBASE_PLATFORM_IOS || \
279-
FIREBASE_PLATFORM_TVOS
280-
EXPECT_EQ(firebase::kFutureStatusPending, result.status());
281-
EXPECT_NE("[email protected]", firebase_user_.email());
282-
firebase::testing::cppsdk::TickerElapse();
283-
#endif // defined(FIREBASE_ANDROID_FOR_DESKTOP) || FIREBASE_PLATFORM_IOS ||
284-
// FIREBASE_PLATFORM_TVOS
285-
MaybeWaitForFuture(result);
286-
EXPECT_EQ(firebase::kFutureStatusComplete, result.status());
287-
EXPECT_EQ(0, result.error());
288-
EXPECT_EQ("[email protected]", firebase_user_.email());
289-
}
290-
291261
TEST_F(UserTest, TestUpdatePassword) {
292262
const std::string config =
293263
std::string(

release_build_files/readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,6 @@ code.
677677
## Release Notes
678678
### Upcoming Release
679679
- Changes
680-
- Auth: Removed deprecated `User::UpdateEmail` method.
681680
- iOS: Added an option to explicitly specify your app's `AppDelegate` class
682681
name via the `FirebaseAppDelegateClassName` key in `Info.plist`. This
683682
provides a more direct way for Firebase to interact with your specified

0 commit comments

Comments
 (0)