Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/analytics_controller.rb
Original file line number Diff line number Diff line change
@@ -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|
Expand All @@ -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
Expand Down
18 changes: 12 additions & 6 deletions app/javascript/app/platform-authenticator.js
Original file line number Diff line number Diff line change
@@ -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;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: rather than an explicit return, I'd wrap the implicit "else" in an explicit else { ... } to make it more obvious that it won't be reached if the condition is false.

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);
});
}
}
Expand Down