action_auth 0.2.14 → 0.2.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40e8b4bf3c3d5177f2b551da1f75a74431389d883d3c254b5278203deac98a59
4
- data.tar.gz: 1555aa754f519bc1161ae5586e76e5ee14d53057e86a7eb5adb7a66bb2611b8a
3
+ metadata.gz: 0e857cd3b20f2efab695368d0b8b127a63cfe1639ef44dc4d346399c8aa446f7
4
+ data.tar.gz: 791837aee1c820e999896082cbdec807b65a0df7db1d29de02b31774682c5448
5
5
  SHA512:
6
- metadata.gz: 12abbb107930bd843549316ff33ac33c3299ebdaebd161849098d6a36b7dbfdfa26c96b97bc73c42764788df7c3fb723395d04dbdcf9960000aca44b1c13be85
7
- data.tar.gz: 81f28336faa6387f2cb2cd4af45a5dcc4b1b7c7817fc908eea2d67664bbb4362c72d349699a743ba4bff2ec39e22343021fc1aa30a052dc6f1ec32b2a5f183bd
6
+ metadata.gz: f881d2e71ec6d1f2f1a5ccc764a9eecb333671163cba5ae8958e4a0b36c408f9670d05e818ce4ff1ab244583f2738f4376f9e8e987cc418748c8fce3217ee4ce
7
+ data.tar.gz: 30773441bd4c9184638cedba7ee4bb8a635f72a761bf6cc6abee5da65c26a4bdbe3cbd4aa72d7774a514276db539818e1b9f89b860c5a790b6a6785a898297d0
@@ -76,24 +76,40 @@ Stimulus.register(
76
76
  }
77
77
  );
78
78
 
79
- document.addEventListener('DOMContentLoaded', function () {
80
- const form = document.getElementById('webauthn_credential_form');
81
- if (form) {
82
- form.addEventListener('submit', function (event) {
83
- event.preventDefault();
84
- const formData = new FormData(form);
85
- fetch(form.action, {
86
- method: 'POST',
87
- body: formData,
88
- headers: {
89
- 'X-CSRF-Token': document.querySelector('[name="csrf-token"]').content
90
- },
91
- credentials: 'same-origin'
92
- }).then(response => {
93
- return response.json();
94
- }).then(data => {
95
- form.dispatchEvent(new CustomEvent('ajax:success', { detail: data }));
79
+ function submitFormWithTurbo(form) {
80
+ const formData = new FormData(form);
81
+ fetch(form.action, {
82
+ method: 'POST',
83
+ body: formData,
84
+ headers: {
85
+ 'X-CSRF-Token': document.querySelector('[name="csrf-token"]').content
86
+ },
87
+ credentials: 'same-origin'
88
+ }).then(response => {
89
+ return response.json();
90
+ }).then(data => {
91
+ form.dispatchEvent(new CustomEvent('ajax:success', { detail: data }));
92
+ });
93
+ }
94
+
95
+ if (!window.Turbo) {
96
+ document.addEventListener('DOMContentLoaded', function () {
97
+ const form = document.getElementById('webauthn_credential_form');
98
+ if (form) {
99
+ form.addEventListener('submit', function (event) {
100
+ event.preventDefault();
101
+ submitFormWithTurbo(form);
96
102
  });
97
- });
98
- }
99
- });
103
+ }
104
+ });
105
+ } else {
106
+ document.addEventListener('turbo:load', function () {
107
+ const form = document.getElementById('webauthn_credential_form');
108
+ if (form) {
109
+ form.addEventListener('submit', function (event) {
110
+ event.preventDefault();
111
+ submitFormWithTurbo(form);
112
+ });
113
+ }
114
+ });
115
+ }
@@ -22,7 +22,9 @@ class ActionAuth::WebauthnCredentialsController < ApplicationController
22
22
 
23
23
  respond_to do |format|
24
24
  format.json { render json: create_options }
25
- format.turbo_stream { render json: create_options, status: :see_other }
25
+ if defined?(Turbo)
26
+ format.turbo_stream { render json: create_options }
27
+ end
26
28
  end
27
29
  end
28
30
 
@@ -1,3 +1,3 @@
1
1
  module ActionAuth
2
- VERSION = "0.2.14"
2
+ VERSION = "0.2.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Kimura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-31 00:00:00.000000000 Z
11
+ date: 2024-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails