janko / rodauth-rails

Rails integration for Rodauth authentication framework
https://github.com/jeremyevans/rodauth
MIT License
565 stars 40 forks source link

Rodauth::Rails.rodauth method should call attributes_before_type_cast on ActiveRecord model #292

Closed dush closed 2 months ago

dush commented 2 months ago

By default rodauth-rails uses integer column to store status and defines enum :status, unverified: 1, verified: 2, closed: 3 in Account model. Whenever instance of such Account model is passed to Rodauth::Rails.rodauth(account: account) it calls attribues method on it. But ActiveRecord attributes returns string values not the integer value stored in database. Then some rodauth internal methods fail, such as

def allow_resending_verify_account_email?
   account[account_status_column] == account_unverified_status_value
end

Where account[account_status_column] returns eg "unverified" while account_unverified_status_value is set to 1. I think Rodauth::Rails.rodauth method shoudl call attributes_before_type_cast on ActiveRecord model.

janko commented 2 months ago

That makes sense to me 👍🏻 Would you like to submit a pull request for it? If not, I could probably work on it next week.

janko commented 2 months ago

Fixed in https://github.com/janko/rodauth-rails/pull/293.