Skip to content

How to sign in a user without a password? #183

Answered by ellmetha
notramo asked this question in Q&A
Discussion options

You must be logged in to vote

@notramo Yes, it is possible with the current implementation and marten-auth allows you to do that easily. You just need to call the User#set_unusable_password method when creating your user record and then call MartenAuth#sign_in with your User record and the current request object at sign in time.

For example:

# At sign up time.
user = User.new(...)
user.set_unusable_password
user.save!

# At sign in time.
MartenAuth.sign_in(user, request)

This technique is used by other shards that provide passwordless authentication, such as msa7/multi_auth. You can check out the Marten example in this repository for a more concrete example.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@notramo
Comment options

@ellmetha
Comment options

Answer selected by ellmetha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants