3939#include " auth/src/desktop/rpcs/secure_token_response.h"
4040#include " auth/src/desktop/rpcs/set_account_info_request.h"
4141#include " auth/src/desktop/rpcs/set_account_info_response.h"
42+ #include " auth/src/desktop/rpcs/sign_up_request.h"
4243#include " auth/src/desktop/rpcs/verify_assertion_request.h"
4344#include " auth/src/desktop/rpcs/verify_assertion_response.h"
4445#include " auth/src/desktop/rpcs/verify_password_request.h"
@@ -256,6 +257,47 @@ void TriggerSaveUserFlow(AuthData* const auth_data) {
256257 }
257258}
258259
260+ template <typename ResponseT, typename ResultT>
261+ void PerformSignUpFlow (AuthDataHandle<ResultT, SignUpRequest>* const handle) {
262+ FIREBASE_ASSERT_RETURN_VOID (handle && handle->request );
263+
264+ const auto response = GetResponse<ResponseT>(*handle->request );
265+ const AuthenticationResult auth_response =
266+ CompleteSignInFlow (handle->auth_data , response);
267+
268+ if (auth_response.IsValid ()) {
269+ const AuthResult auth_result =
270+ auth_response.SetAsCurrentUser (handle->auth_data );
271+ // The usual SignIn flow doesn't trigger this, but since this is used
272+ // to upgrade anonymous accounts, it is needed for SignUp
273+ NotifyIdTokenListeners (handle->auth_data );
274+ CompletePromise (&handle->promise , auth_result);
275+ } else {
276+ FailPromise (&handle->promise , auth_response.error ());
277+ }
278+ }
279+
280+ template <typename ResponseT, typename ResultT>
281+ void PerformSignUpFlow_DEPRECATED (
282+ AuthDataHandle<ResultT, SignUpRequest>* const handle) {
283+ FIREBASE_ASSERT_RETURN_VOID (handle && handle->request );
284+
285+ const auto response = GetResponse<ResponseT>(*handle->request );
286+ const AuthenticationResult auth_response =
287+ CompleteSignInFlow (handle->auth_data , response);
288+
289+ if (auth_response.IsValid ()) {
290+ const SignInResult sign_in_result =
291+ auth_response.SetAsCurrentUser_DEPRECATED (handle->auth_data );
292+ // The usual SignIn flow doesn't trigger this, but since this is used
293+ // to upgrade anonymous accounts, it is needed for SignUp
294+ NotifyIdTokenListeners (handle->auth_data );
295+ CompletePromise (&handle->promise , sign_in_result);
296+ } else {
297+ FailPromise (&handle->promise , auth_response.error ());
298+ }
299+ }
300+
259301template <typename ResultT>
260302void PerformSetAccountInfoFlow (
261303 AuthDataHandle<ResultT, SetAccountInfoRequest>* const handle) {
@@ -306,14 +348,14 @@ Future<ResultT> DoLinkWithEmailAndPassword(
306348 const EmailAuthCredential* email_credential =
307349 GetEmailCredential (raw_credential_impl);
308350
309- typedef SetAccountInfoRequest RequestT;
351+ typedef SignUpRequest RequestT;
310352 auto request = RequestT::CreateLinkWithEmailAndPasswordRequest (
311353 *auth_data->app , GetApiKey (*auth_data),
312354 email_credential->GetEmail ().c_str (),
313355 email_credential->GetPassword ().c_str ());
314356
315357 return CallAsyncWithFreshToken (auth_data, promise, std::move (request),
316- PerformSetAccountInfoFlow<ResultT >);
358+ PerformSignUpFlow<SignUpNewUserResponse >);
317359}
318360
319361// Calls setAccountInfo endpoint to link the current user with the given email
@@ -329,14 +371,15 @@ Future<ResultT> DoLinkWithEmailAndPassword_DEPRECATED(
329371 const EmailAuthCredential* email_credential =
330372 GetEmailCredential (raw_credential_impl);
331373
332- typedef SetAccountInfoRequest RequestT;
374+ typedef SignUpRequest RequestT;
333375 auto request = RequestT::CreateLinkWithEmailAndPasswordRequest (
334376 *auth_data->app , GetApiKey (*auth_data),
335377 email_credential->GetEmail ().c_str (),
336378 email_credential->GetPassword ().c_str ());
337379
338- return CallAsyncWithFreshToken (auth_data, promise, std::move (request),
339- PerformSetAccountInfoFlow_DEPRECATED<ResultT>);
380+ return CallAsyncWithFreshToken (
381+ auth_data, promise, std::move (request),
382+ PerformSignUpFlow_DEPRECATED<SignUpNewUserResponse>);
340383}
341384
342385// Checks that the given provider wasn't already linked to the currently
0 commit comments