I have fully rebuilt a new Rails app but I need to copy the users over from the old app. Both apps use Devise, but I am not sure how to safely copy the encrypted password and have it work on the new app. Thanks.
This is a relatively old topic, but I recently had a similar issue when migrating users from an app to another, both using Devise as auth system.
As discussed above, a valid option is to extract the auth-related fields (email and encrypted_password) from the previous model and insert them in the new one. You'll just have to make sure that you skip the Devise validation steps when populating the new database, otherwise it will require you to provide a valid password.
Therefore this should work :
user = User.new(email: '[email protected]', encrypted_password: 'existing_password_hash')
user.save(validate: false)
If you have a test user with a known password, you can test the results with :
user.valid_password?('my_known_password')
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With