diff --git a/app/controllers/two_factor_authentication/otp_verification_controller.rb b/app/controllers/two_factor_authentication/otp_verification_controller.rb index c505acfbffc..d7614788899 100644 --- a/app/controllers/two_factor_authentication/otp_verification_controller.rb +++ b/app/controllers/two_factor_authentication/otp_verification_controller.rb @@ -36,10 +36,11 @@ def redirect_if_blank_phone end def confirm_multiple_factors_enabled - return if UserSessionContext.confirmation_context?(context) || phone_enabled? + phone_enabled = phone_enabled? + return if UserSessionContext.confirmation_context?(context) || phone_enabled if MfaPolicy.new(current_user).two_factor_enabled? && - !phone_enabled? && user_signed_in? + !phone_enabled && user_signed_in? return redirect_to user_two_factor_authentication_url end @@ -67,10 +68,16 @@ def confirm_voice_capability end def phone - MfaContext.new(current_user).phone_configuration(user_session[:phone_id])&.phone || + phone_configuration&.phone || user_session[:unconfirmed_phone] end + def phone_configuration + return @phone_configuration if defined?(@phone_configuration) + @phone_configuration = + MfaContext.new(current_user).phone_configuration(user_session[:phone_id]) + end + def sanitized_otp_code form_params[:code].to_s.strip end @@ -112,8 +119,7 @@ def analytics_properties area_code: parsed_phone.area_code, country_code: parsed_phone.country, phone_fingerprint: Pii::Fingerprinter.fingerprint(parsed_phone.e164), - phone_configuration_id: user_session[:phone_id] || - current_user.default_phone_configuration&.id, + phone_configuration_id: phone_configuration&.id, in_multi_mfa_selection_flow: in_multi_mfa_selection_flow?, enabled_mfa_methods_count: mfa_context.enabled_mfa_methods_count, } diff --git a/app/controllers/users/two_factor_authentication_controller.rb b/app/controllers/users/two_factor_authentication_controller.rb index b3d4eeec0ed..ce280650bac 100644 --- a/app/controllers/users/two_factor_authentication_controller.rb +++ b/app/controllers/users/two_factor_authentication_controller.rb @@ -66,7 +66,9 @@ def phone_enabled? end def phone_configuration - MfaContext.new(current_user).phone_configuration(user_session[:phone_id]) + return @phone_configuration if defined?(@phone_configuration) + @phone_configuration = + MfaContext.new(current_user).phone_configuration(user_session[:phone_id]) end def validate_otp_delivery_preference_and_send_code