Skip to content

Commit 664b2a2

Browse files
Remove deprecated cpp auth function (#1772)
* Remove deprecated Auth function from C++ SDK Matching a change made in the Unity SDK, this commit removes: - Auth: `User::UpdateEmail` and `User::UpdateEmailLastResult` Updated the release notes to reflect this change. * Remove deprecated User::UpdateEmail from C++ SDK and tests Matching a change made in the Unity SDK, this commit removes: - Auth: `User::UpdateEmail` and `User::UpdateEmailLastResult` methods. Integration tests in `ta/auth/it/src/integration_test.cc` were updated: - Removed a call to `UpdateEmail` on an invalid user. - Commented out calls to `UpdateEmail` in `TestUpdateEmailAndPassword` to allow build to pass. Further work is needed to update this test to the new email verification flow. Updated the release notes to reflect this change. * Remove deprecated User::UpdateEmail from C++ SDK and tests Matching a change made in the Unity SDK, this commit removes: - Auth: `User::UpdateEmail` and `User::UpdateEmailLastResult` methods. Integration tests in `ta/auth/it/src/integration_test.cc` were updated: - Removed a call to `UpdateEmail` on an invalid user. - Removed commented-out calls to `UpdateEmail` in `TestUpdateEmailAndPassword`. Updated the release notes to reflect this change. * 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. * Restore removal. * Restore the readme change. * Format code. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent fb725e9 commit 664b2a2

File tree

9 files changed

+5
-174
lines changed

9 files changed

+5
-174
lines changed

auth/integration_test/src/integration_test.cc

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,6 @@ TEST_F(FirebaseAuthTest, TestOperationsOnInvalidUser) {
580580
WaitForCompletionOrInvalidStatus(string_future, "GetToken");
581581
EXPECT_NE(string_future.error(), firebase::auth::kAuthErrorNone);
582582

583-
LogDebug("Update Email");
584-
void_future = invalid_user.UpdateEmail(GenerateEmailAddress().c_str());
585-
WaitForCompletionOrInvalidStatus(void_future, "UpdateEmail");
586-
EXPECT_NE(void_future.error(), firebase::auth::kAuthErrorNone);
587-
588583
LogDebug("Update Password");
589584
void_future = invalid_user.UpdatePassword(kTestPassword);
590585
WaitForCompletionOrInvalidStatus(void_future, "UpdatePassword");
@@ -766,18 +761,13 @@ TEST_F(FirebaseAuthTest, TestUpdateEmailAndPassword) {
766761
firebase::auth::User user = auth_->current_user();
767762
EXPECT_TRUE(user.is_valid());
768763

769-
// Update the user's email and password.
770-
const std::string new_email = "new_" + email;
771-
WaitForCompletion(user.UpdateEmail(new_email.c_str()), "UpdateEmail");
764+
// Update the user's password.
765+
// Email update functionality has been changed and the old UpdateEmail method
766+
// removed. A more comprehensive test for the new email update flow
767+
// (SendEmailVerificationBeforeUpdatingEmail) would be needed here.
772768
WaitForCompletion(user.UpdatePassword(kTestPasswordUpdated),
773769
"UpdatePassword");
774770

775-
firebase::auth::Credential new_email_cred =
776-
firebase::auth::EmailAuthProvider::GetCredential(new_email.c_str(),
777-
kTestPasswordUpdated);
778-
WaitForCompletion(user.Reauthenticate(new_email_cred), "Reauthenticate");
779-
EXPECT_TRUE(user.is_valid());
780-
781771
WaitForCompletion(user.SendEmailVerification(), "SendEmailVerification");
782772
DeleteUser();
783773
}

auth/src/android/user_android.cc

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ 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;"), \
4644
X(VerifyBeforeUpdateEmail, "verifyBeforeUpdateEmail", \
4745
"(Ljava/lang/String;)Lcom/google/android/gms/tasks/Task;"), \
4846
X(UpdatePassword, "updatePassword", "(Ljava/lang/String;)" \
@@ -353,26 +351,6 @@ std::vector<UserInfoInterface> User::provider_data() const {
353351
return provider_data;
354352
}
355353

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-
376354
Future<void> User::UpdatePassword(const char* password) {
377355
if (!ValidUser(auth_data_)) {
378356
return Future<void>();

auth/src/desktop/user_desktop.cc

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -835,34 +835,6 @@ 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-
866838
Future<void> User::UpdatePassword(const char* const password) {
867839
if (auth_data_ == nullptr) { // user is not valid
868840
return Future<void>(); // invalid future

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,6 @@ 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-
246232
/// Attempts to change the password for the current user.
247233
///
248234
/// For an account linked to an Identity Provider (IDP) with no password,

auth/src/ios/user_ios.mm

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,6 @@ 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-
119105
Future<void> User::UpdatePassword(const char *password) {
120106
if (!ValidUser(auth_data_)) {
121107
return Future<void>();

auth/src/user.cc

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

2222
AUTH_RESULT_FN(User, GetToken, std::string)
23-
AUTH_RESULT_FN(User, UpdateEmail, void)
2423
AUTH_RESULT_FN(User, UpdatePassword, void)
2524
AUTH_RESULT_FN(User, LinkWithCredential, AuthResult)
2625
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ code.
677677
## Release Notes
678678
### Upcoming Release
679679
- Changes
680+
- Auth: Removed deprecated `User::UpdateEmail` method.
680681
- iOS: Added an option to explicitly specify your app's `AppDelegate` class
681682
name via the `FirebaseAppDelegateClassName` key in `Info.plist`. This
682683
provides a more direct way for Firebase to interact with your specified

0 commit comments

Comments
 (0)