Skip to content

Commit 27c1714

Browse files
author
David Revelo
committed
Refactor sign up mutation
1 parent 457c093 commit 27c1714

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

app/graphql/graphql_devise/mutations/sign_up.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ def resolve(confirm_success_url: nil, config_name: nil, **attrs)
1616
if resource.save
1717
yield resource if block_given?
1818

19-
if confirmable_enabled?(resource) && !resource.confirmed?
20-
# user will require email authentication
19+
if requires_confirmation?(resource)
2120
resource.send_confirmation_instructions(
2221
client_config: config_name,
2322
redirect_url: confirm_success_url
2423
)
2524
end
2625

27-
set_auth_headers(resource) if active_for_authentication?(resource)
26+
set_auth_headers(resource) if resource.active_for_authentication?
2827

2928
{ authenticable: resource }
3029
else
@@ -45,8 +44,8 @@ def confirmable_enabled?(resource)
4544
resource.respond_to?(:confirmed_at)
4645
end
4746

48-
def active_for_authentication?(resource)
49-
resource.active_for_authentication?
47+
def requires_confirmation?(resource)
48+
resource.active_for_authentication? || !resource.confirmed?
5049
end
5150

5251
def provider

spec/requests/mutations/sign_up_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
)
3535

3636
user = User.last
37+
3738
expect(user).not_to be_active_for_authentication
3839
expect(user.confirmed_at).to be_nil
3940
expect(user.valid_password?(password)).to be_truthy

0 commit comments

Comments
 (0)