action_auth 0.2.14 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40e8b4bf3c3d5177f2b551da1f75a74431389d883d3c254b5278203deac98a59
4
- data.tar.gz: 1555aa754f519bc1161ae5586e76e5ee14d53057e86a7eb5adb7a66bb2611b8a
3
+ metadata.gz: fa8d3dbc8281ff24b428e82568470f21268c085d94352302c4f5bf4134041526
4
+ data.tar.gz: e266314b2359d22db1983ae7a9a13ddda8fd589819c834ccb5fb5e28418176a6
5
5
  SHA512:
6
- metadata.gz: 12abbb107930bd843549316ff33ac33c3299ebdaebd161849098d6a36b7dbfdfa26c96b97bc73c42764788df7c3fb723395d04dbdcf9960000aca44b1c13be85
7
- data.tar.gz: 81f28336faa6387f2cb2cd4af45a5dcc4b1b7c7817fc908eea2d67664bbb4362c72d349699a743ba4bff2ec39e22343021fc1aa30a052dc6f1ec32b2a5f183bd
6
+ metadata.gz: dd44e5d7bc676a69f0b7d60196a68b02c77ea9c7c042faa3251acce7b937e6a13fa7f8e44d4c982dc1d45a28d6e29124d7489f06649bd97296278964c409d12e
7
+ data.tar.gz: 288208466865e199fd803d5dc57fcb537467c166084be4812261083742de66d3314a86b287f612e261bfba7ed4ebd4c35ddcfd7199ad99de9aac8ea04937dbf1
@@ -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
+ }
@@ -5,13 +5,13 @@ module ActionAuth
5
5
 
6
6
  def show
7
7
  @user.update! verified: true
8
- redirect_to main_app.root_path, notice: "Thank you for verifying your email address"
8
+ redirect_to sign_in_path, notice: "Thank you for verifying your email address"
9
9
  end
10
10
 
11
11
  def create
12
12
  user = ActionAuth::User.find_by(email: params[:email])
13
13
  UserMailer.with(user: user).email_verification.deliver_later if user
14
- redirect_to main_app.root_path, notice: "We sent a verification email to your email address"
14
+ redirect_to sign_in_path, notice: "We sent a verification email to your email address"
15
15
  end
16
16
 
17
17
  private
@@ -27,9 +27,9 @@ module ActionAuth
27
27
  def redirect_to_root
28
28
  if @user.email_previously_changed?
29
29
  resend_email_verification
30
- redirect_to main_app.root_path, notice: "Your email has been changed"
30
+ redirect_to sign_in_path, notice: "Your email has been changed. Check your email to verify your email."
31
31
  else
32
- redirect_to main_app.root_path
32
+ redirect_to sign_in_path
33
33
  end
34
34
  end
35
35
 
@@ -14,7 +14,7 @@ module ActionAuth
14
14
  send_password_reset_email
15
15
  redirect_to sign_in_path, notice: "Check your email for reset instructions"
16
16
  else
17
- redirect_to new_identity_password_reset_path, alert: "You can't reset your password until you verify your email"
17
+ redirect_to sign_in_path, alert: "You can't reset your password until you verify your email"
18
18
  end
19
19
  end
20
20
 
@@ -7,7 +7,7 @@ module ActionAuth
7
7
 
8
8
  def update
9
9
  if @user.update(user_params)
10
- redirect_to main_app.root_path, notice: "Your password has been changed"
10
+ redirect_to sign_in_path, notice: "Your password has been changed"
11
11
  else
12
12
  render :edit, status: :unprocessable_entity
13
13
  end
@@ -10,12 +10,12 @@ module ActionAuth
10
10
  if @user.save
11
11
  if ActionAuth.configuration.verify_email_on_sign_in
12
12
  send_email_verification
13
- redirect_to main_app.root_path, notice: "Welcome! You have signed up successfully. Please check your email to verify your account."
13
+ redirect_to sign_in_path, notice: "Welcome! You have signed up successfully. Please check your email to verify your account."
14
14
  else
15
15
  session_record = @user.action_auth_sessions.create!
16
16
  cookies.signed.permanent[:session_token] = { value: session_record.id, httponly: true }
17
17
 
18
- redirect_to main_app.root_path, notice: "Welcome! You have signed up successfully"
18
+ redirect_to sign_in_path, notice: "Welcome! You have signed up successfully"
19
19
  end
20
20
  else
21
21
  render :new, status: :unprocessable_entity
@@ -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.3.0"
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.3.0
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-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.5.5
123
+ rubygems_version: 3.5.6
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: A simple Rails engine for authorization.