Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add omniauthable_providers config #211

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions app/models/spree/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ 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?
devise :lockable if Spree::Auth::Config[:lockable].present?

if defined?(Spree::SoftDeletable)
include Spree::SoftDeletable
Expand Down
2 changes: 2 additions & 0 deletions lib/spree/auth_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class AuthConfiguration < Preferences::Configuration
preference :registration_step, :boolean, default: true
preference :signout_after_password_change, :boolean, default: true
preference :confirmable, :boolean, default: false
preference :lockable, :boolean, default: false
preference :omniauthable, :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 @@ -100,4 +100,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
11 changes: 11 additions & 0 deletions spec/support/omniauthable_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

RSpec.configure do |config|
config.before do |example|
if example.metadata.key?(:omniauthable)
stub_spree_preferences(Spree::Auth::Config, omniauthable: example.metadata[:omniauthable])

# load File.expand_path('../../../app/models/spree/user.rb', __FILE__)
end
end
end