Integration with Devise #163
Replies: 11 comments
-
Hi! Thanks! I'm not sure I want built-in devise integration. I'd like to keep the two separate. If we just move to use Devise's (Devise is great though - no hate!) Here's what I've done in a "legacy" app that previously used Devise, to keep the users' sessions after migrating to Passwordless: def current_user
@current_user ||=
authenticate_by_cookie(User) ||
fallback_to_old_devise_session
end
def fallback_to_old_devise_session
id = session.fetch('warden.user.user.key', []).dig 0, 0
user = User.find_by(id: id)
return nil unless user
sign_in! user
end It's not necessarily pretty but it worked. What do you think? How can we keep the two separate and still make them work with each other? |
Beta Was this translation helpful? Give feedback.
-
Hey Mikkel, first of all: I like the simplicity of passwordless. Thanks for your work and for publishing it. I am currently evaluating different ways to gradually move towards a "Magic Link"-based (ML) authentication system. The migration should be gradual and not a full replacement for some UX concerns I yet need to refute. Therefore my goal is to offer a new primary ML-based authentication system (e.g. via passwordless) and a secondary password-based authentication system (via devise). Unfortunately both systems do not play well together for the reason that @sergiopantoja pointed out.
I agree that passwordless should definitely NOT depend on Devise (for many reasons) and for greenfield projects many people might not even use Devise anymore. For brownfield projects (with existing users) that already use Devise I think it would very beneficial for passwordless to be able to co-exist Devise. This would allow developers to support a gradual migration from Devise to passwordless ;) What do you think? |
Beta Was this translation helpful? Give feedback.
-
Hi @grekko! I think the two can co-exist with the "fix" I posted above? Just put Passwordless in front of Devise and let it fall back if necessary. The user might end up with two cookies – but that's not necessarily a problem for them. Only problem is that it's probably going to end up confusing to you 😀 |
Beta Was this translation helpful? Give feedback.
-
If you have any specific concerns about mixing the two let me know – I'll see if we can figure something out. But I think going for the simplest possible way is probably the best for both your project and Passwordless. |
Beta Was this translation helpful? Give feedback.
-
Hmm. I observed that Passwordless and Devise where both extending ApplicationController with a
It turned out that I had to jump through some hoops to integrate Passwordless since it is using the In the end I implemented my own MagicLink-Solution which is fairly simple since I am already using Devise (+ Warden) and probably wont be using Passwordless (for now). Nevertheless I like your project and for a greenfield project I would not even go for Devise and instead give Passwordless a try. Also if I am able to turn off password-bases authentication in the near future I might have a look at Passwordless again and be able to completely drop Devise + Warden. So if you are interested I can describe the difficulties I had and provide a PR demonstrating the changes I made to Passwordless to make it work for me. |
Beta Was this translation helpful? Give feedback.
-
Passwordless doesn't touch ApplicationController unless told to (by using I'm very curious what |
Beta Was this translation helpful? Give feedback.
-
I have not much experience w/ Rails engines but I assume the When rendering the |
Beta Was this translation helpful? Give feedback.
-
You are absolutely right. I just thought that if Passwordless would allow to be mixed together with Devise w/o too many manual customizations would make its adoption much easier. I opened two PRs #14 and #15 to describe the other minor issues I stumbled upon. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot. I suppose we could avoid |
Beta Was this translation helpful? Give feedback.
-
Heyo, I've used and enjoyed passwordless before, but I too needed a Devise integration. I took it as an opportunity to try out some ideas, so I ended up making my own gem for it: devise-passwordless. Hopefully you don't mind me mentioning it here @mikker - this page comes up high on the "devise passwordless" google search so just wanted to provide an option to Devise people arriving here looking for one. And now maybe you won't feel like you have to support Devise as much if you don't want to. 😄 |
Beta Was this translation helpful? Give feedback.
-
@abevoelker Very ok! Nice work 👏 |
Beta Was this translation helpful? Give feedback.
-
Hi! I love this gem and the codebase looks great.
I'd love to integrate it with my current app that uses Devise. I can write a PR if you prefer.
It seems like we could hook into this line:
passwordless/app/controllers/passwordless/sessions_controller.rb
Line 45 in 51c1993
Instead of using the passwordless
#sign_in
method, we could use the Devise#sign_in
method which will accept the sameauthenticatable
object.Or the passwordless
#sign_in
could check if Devise is enabled, and then call out to that.Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions