standard_id 0.5.2 → 0.6.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: 514c8e8c18bb9bf6d8bd0268cca374d477b2c276a3caf69b0ef58222b5b14b33
4
- data.tar.gz: 8e9f2307f6fd2d6a99e78df4604f838c319a61487e0d1549df1712eaf683b639
3
+ metadata.gz: e7f12cdcd431146c994f1ae5b1bf0919357fc7abf8e3668d13363e22eb421fe0
4
+ data.tar.gz: 2017963a39eb1430206fdc8ebf8354c12fc9fa46b755a7706452cb06ac6352b1
5
5
  SHA512:
6
- metadata.gz: 21fcdb6b8caaf652bdbe6cb86c52e7cf66480b5aae7bf9fab210dad86b9cb12626920190cd1743c138d8b3fc1608c2f921a3c18b79f0cdfe20407530fbcee596
7
- data.tar.gz: 30dfa2dae9df664b4ff7bfdb972cbc3970bf8ac81fb185e8f6aca0676b4647903f20e60d0eaf5d531b3e3a1e4fcbaf923b1e05ee7f9f8fd6ca93461b0567e999
6
+ metadata.gz: 61b5e5a16dca753e8128300fb88b37e931252f05e73cfccc5fbc7467e4c58eca7435bc004877eca56c59305310de40c56b0491856cc173cddd5c815bf72b42c9
7
+ data.tar.gz: 1af3914e27993f6a51bb15fc821f40c8bd2095744e0187b107a2273ca70ab006e4c9a5522c3001db6f7f1240345e744fc7805ba5970410f2f263382bbb8c36cd
@@ -19,7 +19,7 @@ module StandardId
19
19
  request,
20
20
  account:,
21
21
  connection: provider.provider_name,
22
- scopes: params[:scope] || params[:scopes]
22
+ scopes: params[:scope]
23
23
  )
24
24
 
25
25
  token_response = flow.execute
@@ -10,5 +10,48 @@ module StandardId
10
10
 
11
11
  accepts_nested_attributes_for :identifiers
12
12
  end
13
+
14
+ class_methods do
15
+ def find_or_create_by_verified_email!(email, **account_attributes)
16
+ raise ArgumentError, "email is required" if email.blank?
17
+
18
+ normalized_email = email.to_s.strip.downcase
19
+
20
+ identifier = StandardId::EmailIdentifier.includes(:account).find_by(value: normalized_email)
21
+ return identifier.account if identifier.present?
22
+
23
+ # Best-effort intent signal — fires before create! so subscribers may see
24
+ # ACCOUNT_CREATING without a matching ACCOUNT_CREATED if create! raises.
25
+ StandardId::Events.publish(
26
+ StandardId::Events::ACCOUNT_CREATING,
27
+ email: normalized_email,
28
+ source: "find_or_create_by_verified_email"
29
+ )
30
+
31
+ merged_attributes = account_attributes.dup
32
+ merged_attributes[:email] = normalized_email if column_names.include?("email") && !merged_attributes.key?(:email)
33
+
34
+ account = create!(
35
+ **merged_attributes,
36
+ identifiers_attributes: [
37
+ { type: "StandardId::EmailIdentifier", value: normalized_email, verified_at: Time.current }
38
+ ]
39
+ )
40
+
41
+ StandardId::Events.publish(
42
+ StandardId::Events::ACCOUNT_CREATED,
43
+ account: account,
44
+ email: normalized_email,
45
+ source: "find_or_create_by_verified_email"
46
+ )
47
+
48
+ account
49
+ rescue ActiveRecord::RecordNotUnique
50
+ identifier = StandardId::EmailIdentifier.includes(:account).find_by(value: normalized_email)
51
+ raise unless identifier
52
+
53
+ identifier.account
54
+ end
55
+ end
13
56
  end
14
57
  end
@@ -12,11 +12,7 @@ module StandardId
12
12
  end
13
13
 
14
14
  def find_or_create_account!(email)
15
- identifier = StandardId::EmailIdentifier.includes(:account).find_by(value: email)
16
- return identifier.account if identifier.present?
17
-
18
- identifiers_attributes = [{ type: "StandardId::EmailIdentifier", value: email, verified_at: Time.current }]
19
- Account.create!(identifiers_attributes:)
15
+ Account.find_or_create_by_verified_email!(email)
20
16
  end
21
17
 
22
18
  def sender_callback
@@ -1,3 +1,3 @@
1
1
  module StandardId
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaryl Sim