sorcery icon indicating copy to clipboard operation
sorcery copied to clipboard

External submodule broken with custom authentications relation name

Open arnvald opened this issue 10 years ago • 2 comments

We call this code:

current_user.send(config.authentications_class.name.underscore.pluralize)

when looking for user authentications. This works if the name of relation is just plural form of the class (Authentication -> user.authentications). Problem appears with following code:

#sorcery.rb
user.authentications_class = Authentication

#user.rb
has_many :providers, class_name: "Authentication"

I'm not sure what to do with this one, yet. Either add some information, that relation will not work properly with class_name option, or add another config option, that will describe relation name, but if not specified, will default to plural form of class name.

arnvald avatar Jul 12 '14 16:07 arnvald

I suggest to remove the config option and to use data from user.providers relation.

kirs avatar Jul 14 '14 08:07 kirs

Sounds good, but I'm not sure how to proceed with deprecation. This will be compatibility-breaking change, so we can remove this option in v0.9

What until then? We could add deprecation warning to #authentication_class= method, switch to providers and define providers like this?

def providers
  warn("In order to use external submodule you need to define 'providers' relation")
  sorcery_config.authentication_class.to_s.underscore.pluralize
end

We could introduce this change in 0.8.7 and remove our providers method in 0.9 or 1.0

arnvald avatar Jul 14 '14 09:07 arnvald