Skip to content
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

How to have passwordless work alongside conventional authentication #7

Closed
githubble01 opened this issue Sep 29, 2021 · 6 comments
Closed

Comments

@githubble01
Copy link

Hi!

I'd be happy to get some pointers on how to implement passwordless alongside conventional user/password authentiation.

The instructions are explains how to replace conventional username/password with passwordless.

@abevoelker
Copy link
Owner

Are you referring to having both login strategies on the same model (e.g. User)? Or having separate models for each different strategy (e.g. PasswordUser and PasswordlessUser)?

The former I haven't tested, and may be possible although it would be a pain. The latter, see the multiple user section of the README. You'll want to be sure to follow the "scoped views" section instructions so that your passwordless model has different login view forms than the username/password one.

@githubble01
Copy link
Author

Yes, having both login strategies on the same model is what I mean.

I think I've managed to solve it for my app quite simply though. In my app there is no passwordless signing-up in the front end. The user is required to send a passwordless sign-up request via email.

After having received the passwordless sign-up request email, the app creates an account and sends a magic link back. This way, the front-end doesn't have to be "aware" och the magic link strategy. The user still is able to create a password using the existing "forgot password routine".

This is how I did it. I left the devise_for as is and changed the devise_scope according to the instructions.

# User account
devise_for :users,
  controllers: {
    omniauth_callbacks: "users/omniauth_callbacks",
    registrations: "users/registrations",
    sessions: "users/sessions" 
  }

devise_scope :user do
  get "session/otp", to: "sessions#otp"
  get "/users/magic_link",
      to: "devise/passwordless/magic_links#show",
      as: "users_magic_link"
end

@abevoelker
Copy link
Owner

Great, glad you figured it out and thanks for sharing what worked for you in case future users have a similar need. Closing this unless there's anything else. Thanks.

@brandoncc
Copy link

I have a need for this, so thanks for sharing your solution @githubble01

@ryanfb
Copy link

ryanfb commented Mar 13, 2022

Thanks to the pointers here, I was able to implement a slightly different method of having devise-passwordless work alongside conventional password-based authentication where it still gets used as the sessions controller, which I've written up in a blog post: Flexible Passwordless Rails Authentication with devise-passwordless

@abevoelker
Copy link
Owner

abevoelker commented Mar 13, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants