ruby-on-railsrubyspreespree-auth-devise

Spree Associate user with order with Login


I have a Spree application with the ability to login with Facebook and other social networks , but my problem is that i can't associate user with orders in login , i've tried associate_user! like my following sample but the cart is always empty .

here's my code in omniauthcallback

if current_order
    current_user = spree_current_user || @user
    current_order.associate_user!(current_user)
    session[:guest_token] = nil
end

Solution

  • I Figured out that it's a bug in Spree_auth_devise and it has been solved in version 3.2.0.beta which will be out soon , the problem was in Wardan.rb

    Warden::Manager.after_set_user except: :fetch do |user, auth, opts|
      if auth.cookies.signed[:guest_token].present?
        if user.is_a?(Spree::User)
          Spree::Order.where(email: user.email, guest_token: auth.cookies.signed[:guest_token], user_id: nil).each do |order|
            order.associate_user!(user)
          end
        end
      end
    end
    

    You need to remove this part from the code above email: user.email