riverrun / phauxth

Not actively maintained - Authentication library for Phoenix, and other Plug-based, web applications
409 stars 20 forks source link

Phauxth.Confirm.Report pattern matching #54

Closed evanwang22 closed 6 years ago

evanwang22 commented 6 years ago

Thanks for developing Phauxth. I've added the library incrementally to my project; I started by running mix phauxth.new a while back, and today manually pulled in code generated by the --confirm flag.

While testing password resets I kept receiving the error message "user already confirmed" which was confusing. After digging I realized I was matching into line 27 of Phauxth.Confirm.Report:

def report(%{} = user, _, meta) do
    Log.warn(%Log{user: user.id, message: "user already confirmed", meta: meta})
    {:error, Config.user_messages().already_confirmed()}
  end

because my users table did not have the reset_sent_at column.

I'm guessing others may also upgrade incrementally in the future. Although I recognize I didn't follow the recommended installation method, it would have helped debugging if the pattern matching in Phauxth.Confirm.Report was more specific and an exception occurred -- happy to submit a small PR if you think this would be a good addition

riverrun commented 6 years ago

Hi. Sorry for the delay in getting back to you - I'm really busy at the moment.

With password resets, you need to use the keyword argument mode: :pass_reset with the Confirm.verify function. In version 2, which I am going to release soon, this will change, and then you will need to run Confirm.PassReset.verify.

If you have any further questions, please let me know.

evanwang22 commented 6 years ago

Sorry for the slow follow up. My original comment could've been slightly more precise -- the point of my suggestion was that even when passing mode: :pass_reset you'll still receive "user already confirmed" if the database column is missing -- but if version 2 will be released shortly with the change you mention it's likely to be irrelevant anyhow. Thanks for providing the library and will close this issue.