Skip to content

Commit

Permalink
feat: add omniauthable_providers config
Browse files Browse the repository at this point in the history
  • Loading branch information
zernie committed May 16, 2021
1 parent 09841c1 commit 0099910
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ Devise.setup do |config|
end
```

### Omniauthable

To enable Devise's Omniauthable module, you must follow the [devise wiki](https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview) with _just one exception_:
Instead of adding
```ruby
devise :omniauthable, omniauth_providers: %i[...]
```
you should add this line to an initializer (typically `config/initializers/spree.rb`):

```ruby
Spree::Auth::Config[:omniauthable_providers] = %i[...]
```

Using in an existing application
--------------------------------

Expand Down
1 change: 1 addition & 0 deletions app/models/spree/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class User < Spree::Base
devise :database_authenticatable, :registerable, :recoverable,
:rememberable, :trackable, :validatable, :encryptable
devise :confirmable if Spree::Auth::Config[:confirmable]
devise :omniauthable, omniauth_providers: Spree::Auth::Config[:omniauthable] if Spree::Auth::Config[:omniauthable].present?

acts_as_paranoid
after_destroy :scramble_email_and_password
Expand Down
1 change: 1 addition & 0 deletions lib/spree/auth_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class AuthConfiguration < Preferences::Configuration
preference :registration_step, :boolean, default: true
preference :signout_after_password_change, :boolean, default: true
preference :confirmable, :boolean, default: false
preference :omniauthable_providers, :array, default: []
preference :draw_frontend_routes, :boolean, default: true
preference :draw_backend_routes, :boolean, default: true
end
Expand Down
10 changes: 10 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,14 @@
expect(Spree::User.ancestors).not_to include(Devise::Models::Confirmable)
end
end

describe "omniauthable" do
it "loads Devise's :omniauthable module when :omniauthable is set", omniauthable: %[twitter] do
expect(Spree::User.ancestors).to include(Devise::Models::Omniauthable)
end

it "does not load Devise's :omniauthable module when :omniauthable is nil", omniauthable: nil do
expect(Spree::User.ancestors).not_to include(Devise::Models::Omniauthable)
end
end
end
7 changes: 7 additions & 0 deletions spec/support/confirm_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@

Spree.send(:remove_const, :User)
load File.expand_path('../../../app/models/spree/user.rb', __FILE__)
end

if example.metadata.key?(:omniauthable)
stub_spree_preferences(Spree::Auth::Config, omniauthable: example.metadata[:omniauthable])

# Spree.send(:remove_const, :User)
# load File.expand_path('../../../app/models/spree/user.rb', __FILE__)
end
end
end

0 comments on commit 0099910

Please sign in to comment.