0

I have this problem in ActiveAdmin. When I try to reset a user's password with devise send_reset_password_instructions.

member_action :reset_password, method: :get do
    resource.send_reset_password_instructions
    redirect_to users_path, notice: "instructions sent"
end 

I receive the email but when I try to set the new password I get the error reset password token is invalid. When I do the same process but within my webapp, the token is valid and the new password is set.

Any ideas/suggestions?

2
  • Have you confirmed the token on the user record is the same as that in the email? Commented Feb 5 at 22:13
  • @dbugger for example, after triggering the email, I can see in my database the reset_password_token is '960f2c60a9534ad38f86c36bd7612a5c0e379fb075f862f8f0a833f606c83b21' but the url generated by the email is 'myapp.lvh.me:3000/auth/users/password/…' . Its a shorter/different token . But same thing when it's from the 'forgot password?' view and in that case is works perfectly. Commented Feb 6 at 11:55

1 Answer 1

0

Thanks to cursor ai, I finally made it work. I had to make a custom mailer and encrypt the 'public' token using Devise token_generator and then pass that token to the url. Like this:

encrypted_token = Devise.token_generator.digest(record, :reset_password_token, token)
record.reset_password_token = encrypted_token
record.reset_password_sent_at = Time.now.utc
record.save(validate: false)

@url = edit_password_url(record, reset_password_token: @token,
                                 subdomain: my_subdomain)

Now it works through ActiveAdmin and the web itself. Hope it helps someone

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.