spree_social icon indicating copy to clipboard operation
spree_social copied to clipboard

spree frontend MyAccount Link is not working

Open mohansiriga7 opened this issue 7 years ago • 5 comments

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

  1. 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.

mohansiriga7 avatar May 09 '17 06:05 mohansiriga7

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 %>

mihiic avatar May 18 '17 07:05 mihiic

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.

mohansiriga7 avatar May 19 '17 12:05 mohansiriga7

@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.

mihiic avatar May 20 '17 11:05 mihiic

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

mohansiriga7 avatar May 23 '17 06:05 mohansiriga7

resolved the same issue with the suggested workaround. Thanks!

LucaDev13 avatar Jan 09 '19 22:01 LucaDev13