external? turned true when password and password confirmation is nil
I try to implement simple password authentication and oauth login with sorcery to my app.
when I try to signup without password and password confirmation, external? has been true
here's my code
class User < ActiveRecord::Base
authenticates_with_sorcery!
authenticates_with_sorcery! do |config|
config.authentications_class = Authentication
end
validates :password, presence: true, if: :password_required?
validates :password, confirmation: true, if: :password_required?
validates :password, length: { minimum: 8 }, allow_blank: true
private
def password_required?
new_record? && !external?
end
end
In password_required?, external? has been true and validation has been ignored when password and password_confirmation is nil.
How can I turn on validation in this case?
Hey @takashi, the implementation of external? in Sorcery is not great. You can change it for example to:
def external?
authentications.present?
end
This way users will not require password only if they have at least one authentication assigned (i.e. that they come from some oAuth provider)
Hi @arnvald,
thank you for giving me the good solution. I'd like to implement ur solution as default implementation of sorcery's external? . is there any reason not to implement external? this way?