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

spree frontend MyAccount Link is not working #202

Open
mohansiriga7 opened this issue May 9, 2017 · 5 comments
Open

spree frontend MyAccount Link is not working #202

mohansiriga7 opened this issue May 9, 2017 · 5 comments

Comments

@mohansiriga7
Copy link

mohansiriga7 commented May 9, 2017

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.

@mihiic
Copy link

mihiic commented May 18, 2017

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
Copy link
Author

mohansiriga7 commented May 19, 2017

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
Copy link

mihiic commented May 20, 2017

@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
Copy link
Author

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

@LucaDev13
Copy link

resolved the same issue with the suggested workaround. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants