jeremyevans / rodauth

Ruby's Most Advanced Authentication Framework
http://rodauth.jeremyevans.net
MIT License
1.65k stars 95 forks source link

Add `account_from_id` for loading account by id #431

Closed janko closed 1 week ago

janko commented 1 week ago

This is useful in when delivering emails in a background job, where the background job is given the account ID. In that case, the Rodauth instance needs to be initialized outside of a request, and account and token loaded into it.

This is what rodauth-rails has been doing so far:

rodauth = RodauthApp.rodauth.allocate
rodauth.instance_eval { @account = account_ds(account_id).first! }

With the new method it can be cleaner:

rodauth = RodauthApp.rodauth.allocate
rodauth.account_from_id(account_id)

There are also several places within Rodauth that can make use of this method.