spree-contrib / spree_social

Building block for spree social networking features (provides authentication and account linkage)
http://guides.spreecommerce.org
BSD 3-Clause "New" or "Revised" License
213 stars 283 forks source link

spree frontend MyAccount Link is not working #202

Open mohansiriga7 opened 7 years ago

mohansiriga7 commented 7 years ago

Hi, I am currently using Spree_social gem for facebook and g+ authentication. Whenever i add any authentication methods like FB/G+ in admin panel, i am getting errors for normal users who are logged in with username and password. Steps to reproduce errors: 1) Logged in with normal user and clicking on MyAccount button giving below exception

selection_016 selection_017

2) Trying to login with wrong credentials as normal user giving below exception.

selection_020 selection_021

However if i logged in with facebook then clicking on MyAccount button is working fine. The button is not working only for normal users after i added FB authentication method in admin panel. Please help me with this. Any advice would be much appreciated. Thanks.

mihiic commented 7 years ago

In app/views/spree/shared/_social.html.erb @spree_user is used but the variable name is @user.

Workaround: Override _social.html.erb partial.

Copy existing partial from gem to views/spree/shared/_social.html.erb . Add this line <% user = @spree_user || @user %> and change @spree_user appearances to user. Example:

<% user = @spree_user || @user %>
  <% Spree::AuthenticationMethod.available_for(user).each do |method| %>
      <%= link_to(content_tag(:i, '', class: "icon-spree-#{method.provider.to_url}-circled"),
                  omniauth_authorize_url(user, method.provider),
                  ...
  <% end %>
mohansiriga7 commented 7 years ago

Thanks a lot @mihiic . Now "MyAccount" button is working fine for all three users which i have tested with normal user, facebook user and google user. Trying to fix invalid credentials issue now. Please let me know @mihiic , if you have any suggestions regarding that issue. Thanks.

mihiic commented 7 years ago

@mohansiriga7 You can fix that by adding Spree::User.new to the user definition.

<% user = @spree_user || @user || Spree::User.new %>

This should also fix all crashes of that kind throughout application. It might change Spree intended behavior somewhere, but I have not found such place. (nor would it matter much since it doesn't work as intended anyway)

Explanation of fix Basically what that partial does, it checks which login methods are available to current user. If you are logged in, it only offers you to connect multiple social networks to your account. If user is blank (Spree::User.new) it will offer you all login methods. I suppose they wanted this to also work with nil value, but somehow managed to miss it. Hope this clarifies stuff a bit.

mohansiriga7 commented 7 years ago

@mihiic everything is working fine now. I really appreciate your help in resolving my problems. Thanks

LucaDev13 commented 5 years ago

resolved the same issue with the suggested workaround. Thanks!