diff --git a/app/controllers/analytics_controller.rb b/app/controllers/analytics_controller.rb index 8aab1da92d0..87bd97f62f6 100644 --- a/app/controllers/analytics_controller.rb +++ b/app/controllers/analytics_controller.rb @@ -1,6 +1,5 @@ class AnalyticsController < ApplicationController skip_before_action :verify_authenticity_token - before_action :confirm_two_factor_authenticated def create results.each do |event, result| @@ -20,6 +19,7 @@ def results end def platform_authenticator_result + return unless current_user return if platform_authenticator_results_saved? || !platform_authenticator_params_valid? session[:platform_authenticator_analytics_saved] = true diff --git a/app/javascript/app/platform-authenticator.js b/app/javascript/app/platform-authenticator.js index 4131e33be9c..b670c183265 100644 --- a/app/javascript/app/platform-authenticator.js +++ b/app/javascript/app/platform-authenticator.js @@ -1,12 +1,18 @@ +function postPlatformAuthenticator(userIntent) { + const xhr = new XMLHttpRequest(); + xhr.open('POST', '/analytics', true); + xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + xhr.send(`platform_authenticator[available]=${userIntent}`); +} function platformAuthenticator() { - const isEnabled = document.querySelector('[data-platform-authenticator-enabled]'); - if (isEnabled && window.PublicKeyCredential) { + if (document.querySelector('[data-platform-authenticator-enabled]')) { + if (!window.PublicKeyCredential) { + postPlatformAuthenticator(false); + return; + } window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable() .then(function(userIntent) { - const xhr = new XMLHttpRequest(); - xhr.open('POST', '/analytics', true); - xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); - xhr.send(`platform_authenticator[available]=${userIntent}`); + postPlatformAuthenticator(userIntent); }); } }