-
Notifications
You must be signed in to change notification settings - Fork 40
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
Only overwrite password_required? / password if undefined #13
Comments
Sounds like a good idea for now - if you want to make a PR I'd accept it. I haven't done much yet with mixing passwordless + password (database_authenticatable) in the same model yet but I'd definitely like to support it better as I know there is demand (e.g. #7). One thought is that apps using both of these modules together may have different semantic expectations for their users logging in, e.g.
Presumably different semantics may lead to different implementations of the two methods you highlighted based on which type of user is logging in? In any case I can think about it more and deal with it later |
I have exactly that need, and solved it by adding an I monkey-patched the authentication strategy to check for that: module OptionalMagicLinkAuthentication
def validate(resource, &block)
super { resource.active_for_magic_link_authentication? }
end
end
Devise::Strategies::MagicLinkAuthenticatable.include(OptionalMagicLinkAuthentication) And I also adjusted |
#32 fixes this |
I'm a year late but this should now be fixed on master via adc78bb @fschwahn I appreciate your suggestions as that's the approach I ended up taking! 🤘 Thanks for your contributions in opening this and providing code snippets. I just have one final breaking change to implement (#36) before finalizing the 1.0 gem release, which I hope to have ready for tomorrow. I am now closing this issue as resolved, but feel free to re-open if I've missed something or if you have other concerns. 🙇 |
Great, thank you! |
…`database_authenticatable` strategy This fix properly ensures that the `#password_required?` and `#password` methods are not redefined by `Devise::Models::MagicLinkAuthenticatable` if they already exist in the model. The check for the existing methods via `instance_methods.include?` must be done in the context of the class the module is being included into and not in the module itself. See abevoelker#13 for full context.
…`database_authenticatable` and `validatable` modules. This fix properly ensures that the `#password_required?` and `#password` methods are not redefined by `Devise::Models::MagicLinkAuthenticatable` if they already exist in the model. The check for the existing methods via `instance_methods.include?` must be done in the context of the class the module is being included into and not in the module itself. See abevoelker#13 for full context.
Unfortunately the fix in adc78bb doesn’t appear to actually solve the problem here as far as I can tell. If you’re using the My first thought was to wrap the conditional in I don’t see an obvious way to fix this to support both use cases (authentication only by So, I’m not sure how to fix this but unfortunately I think it’s still not working correctly currently! I have a draft PR at #56 which has the fix with For context, I have a slightly different use case than those I’ve seen discussed anywhere else so far. We have regular users that always log in via password, but need to generate passwordless login links that are provided to a separate customer service application via an API that ultimately give customer service agents the ability to log in as a user when dealing with customer service requests. I feel like this gem is a bit too opinionated regarding the assumption that passwordless authentication is going to replace all other forms of authentication, when it really could just be a general provider of a passwordless authentication strategy that may or may not coexist with alternate methods. |
For anyone else trying to figure out what you have to do here to strictly add authentication via (and generation of) magic links, but keep everything else about your current authentication set up exactly the same, this gem supports it and makes it easy, but I couldn’t find a clearly articulated step-by-step method for doing so. This is what worked for me:
Note that you do not need to make any changes to your existing routes. |
…`database_authenticatable` and `validatable` modules. This fix properly ensures that the `#password_required?` and `#password` methods are not redefined by `Devise::Models::MagicLinkAuthenticatable` if they already exist in the model. The check for the existing methods via `instance_methods.include?` must be done in the context of the class the module is being included into and not in the module itself. See #13 for full context.
I'm using magic links along with the possibility to use email/password (ie. database_authenticatable). The methods from
database_authenticatable
are overwritten indevise-passwordless/lib/devise/models/magic_link_authenticatable.rb
Lines 8 to 15 in c38db38
Would it be possible to define those methods only if they are previously undefined?
The text was updated successfully, but these errors were encountered: