Understanding spree_auth_devise gem

156 views
Skip to first unread message

Brandon Hay

unread,
Dec 4, 2014, 8:14:07 AM12/4/14
to spree...@googlegroups.com
Hi,

I'd like to better understand the Spree Auth Devise gem and why exactly I need it. My RoR application is set up with an existing Devise Authentication and the user class is "User". I've followed the guide on customizing authentication and I have found that there seems to be a conflict between my Devise v 3.2.3 and spree_auth_devise 2-3-stable. 

To sum up the problem:

When I have spree_auth_devise listed in my gemfile, the Spree.user_class that I edited to reference my User class gets overridden to "Spree::User". This leads to errors like undefined methods, since that Spree user class is foreign to my app. However, when I delete the spree_auth_devise gem from my gemfile, for some reason the Spree.user_class does become my "User" class and everything works fine.

When someone tries to pull down my repo with spree auth devise missing, they get an error because the migrations fail to run. This leads me to believe that I shouldn't just delete the spree_auth_devise gem as I suspect it will also prevent me from having a clean deploy to Heroku, Can anyone tell me more about what this gem does and why exactly it overrides my change in the initializers/spree.rb for my custom user class.

I've asked this question on Stack Overflow recently. Please take a look at it here for reference:

Thanks!

Ben Morgan

unread,
Dec 4, 2014, 4:20:09 PM12/4/14
to spree...@googlegroups.com
Spree Auth Devise should be overwriting it. If I take a peek at the views it appears its looking for Spree::User and not Spree.user_class.

https://github.com/spree/spree_auth_devise/blob/master/lib/views/frontend/spree/shared/_login.html.erb#L1

I would recommend overwriting the views or C&P as if it was an example app if its causing a lot of trouble.

Best regards,

Ben A. Morgan

Jeff Dutil

unread,
Dec 4, 2014, 10:58:31 PM12/4/14
to spree...@googlegroups.com
Correct spree_auth_devise overrides your Spree.user_class here:

You should not be using spree_auth_devise at all if you have implemented your own user model.  You should only use spree_auth_devise as an example of how to implement your own authentication system it's not meant to work with other implementations.  We could probably look into changing the references of Spree::User in the views to just Spree.user_class in order to make these work better side to side, but I wouldn't be surprised if there are other issues mixing this extension with your own devise setup.

Brandon Hay

unread,
Dec 5, 2014, 12:01:39 PM12/5/14
to spree...@googlegroups.com
Alright, that is great information to know. Maybe consider adding a brief point on the spree guides then that if you have an existing User model, DO NOT USE spree_auth_devise to make that painfully obvious. Would have saved me a lot of time anyway.

Thanks for the replies!

Jeff Dutil

unread,
Dec 5, 2014, 3:10:06 PM12/5/14
to spree...@googlegroups.com
Would you mind submitting a PR improving the guide that misled you?  Having someone that's not as familiar with the process, and better understands what led them astray would be a nice improvement.  I'm not sure which guide your referring to, but there is this one:

I could see how that may be confusing that it's shown in the "Background" section, but that guide definitely doesn't mean for you to use spree_auth_devise.  If you read it it's saying that this is the alternative tutorial to using spree_auth_devise.  I guess that isn't obvious enough though as I've heard this a couple times now.  Just not sure how to make it read better other than I suppose a big ass warning saying no don't do this in the background section.

Brandon Hay

unread,
Dec 7, 2014, 2:32:09 AM12/7/14
to spree...@googlegroups.com
How about "Use spree_auth_devise only if you HAVE NOT already setup Devise in your rails app. If you bundle spree_auth_devise then it will OVERRIDE YOUR SPREE USER CLASS THAT YOU SET UP IN config/initializers/spree.rb!!!"
Reply all
Reply to author
Forward
0 new messages