Sha256: ffeca79bfb0d55ee076d936191ebaba9c7803656b18371bb15b06434979f8cd5

Contents?: true

Size: 596 Bytes

Versions: 13

Compression:

Stored size: 596 Bytes

Contents

# Merges users orders to their account after sign in and sign up.
Warden::Manager.after_set_user except: :fetch do |user, auth, _opts|
  token = auth.cookies.signed[:guest_token] || auth.cookies.signed[:token]
  token_attr = Spree::Order.has_attribute?(:token) ? :token : :guest_token

  if token.present? && user.is_a?(Spree::User)
    Spree::Order.incomplete.where(token_attr => token, user_id: nil).each do |order|
      order.associate_user!(user)
    end
  end
end 

Warden::Manager.before_logout do |_user, auth, _opts|
  auth.cookies.delete(:guest_token)
  auth.cookies.delete(:token)
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
spree_auth_devise-4.0.1 config/initializers/warden.rb
spree_auth_devise-4.1.1 config/initializers/warden.rb
spree_auth_devise-4.2.1 config/initializers/warden.rb
spree_auth_devise-4.3.2 config/initializers/warden.rb
spree_auth_devise-4.3.1 config/initializers/warden.rb
spree_auth_devise-4.3.0 config/initializers/warden.rb
spree_auth_devise-4.2.0 config/initializers/warden.rb
spree_auth_devise-4.1.0 config/initializers/warden.rb
spree_auth_devise-4.1.0.rc1 config/initializers/warden.rb
spree_auth_devise-4.0.0 config/initializers/warden.rb
spree_auth_devise-4.0.0.rc2 config/initializers/warden.rb
spree_auth_devise-4.0.0.rc1 config/initializers/warden.rb
spree_auth_devise-3.5.2 config/initializers/warden.rb