Skip to content

Commit 0099910

Browse files
committed
feat: add omniauthable_providers config
1 parent 09841c1 commit 0099910

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ Devise.setup do |config|
5252
end
5353
```
5454

55+
### Omniauthable
56+
57+
To enable Devise's Omniauthable module, you must follow the [devise wiki](https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview) with _just one exception_:
58+
Instead of adding
59+
```ruby
60+
devise :omniauthable, omniauth_providers: %i[...]
61+
```
62+
you should add this line to an initializer (typically `config/initializers/spree.rb`):
63+
64+
```ruby
65+
Spree::Auth::Config[:omniauthable_providers] = %i[...]
66+
```
67+
5568
Using in an existing application
5669
--------------------------------
5770

app/models/spree/user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class User < Spree::Base
99
devise :database_authenticatable, :registerable, :recoverable,
1010
:rememberable, :trackable, :validatable, :encryptable
1111
devise :confirmable if Spree::Auth::Config[:confirmable]
12+
devise :omniauthable, omniauth_providers: Spree::Auth::Config[:omniauthable] if Spree::Auth::Config[:omniauthable].present?
1213

1314
acts_as_paranoid
1415
after_destroy :scramble_email_and_password

lib/spree/auth_configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class AuthConfiguration < Preferences::Configuration
55
preference :registration_step, :boolean, default: true
66
preference :signout_after_password_change, :boolean, default: true
77
preference :confirmable, :boolean, default: false
8+
preference :omniauthable_providers, :array, default: []
89
preference :draw_frontend_routes, :boolean, default: true
910
preference :draw_backend_routes, :boolean, default: true
1011
end

spec/models/user_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,14 @@
9696
expect(Spree::User.ancestors).not_to include(Devise::Models::Confirmable)
9797
end
9898
end
99+
100+
describe "omniauthable" do
101+
it "loads Devise's :omniauthable module when :omniauthable is set", omniauthable: %[twitter] do
102+
expect(Spree::User.ancestors).to include(Devise::Models::Omniauthable)
103+
end
104+
105+
it "does not load Devise's :omniauthable module when :omniauthable is nil", omniauthable: nil do
106+
expect(Spree::User.ancestors).not_to include(Devise::Models::Omniauthable)
107+
end
108+
end
99109
end

spec/support/confirm_helpers.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121

2222
Spree.send(:remove_const, :User)
2323
load File.expand_path('../../../app/models/spree/user.rb', __FILE__)
24+
end
25+
26+
if example.metadata.key?(:omniauthable)
27+
stub_spree_preferences(Spree::Auth::Config, omniauthable: example.metadata[:omniauthable])
28+
29+
# Spree.send(:remove_const, :User)
30+
# load File.expand_path('../../../app/models/spree/user.rb', __FILE__)
2431
end
2532
end
2633
end

0 commit comments

Comments
 (0)