janko / rodauth-rails

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

Documentation on rodauth internal_request is confusing #61

Closed Bertg closed 2 years ago

Bertg commented 2 years ago

Hi,

I just started using rodauth and rodauth_rails. I wanted to start using the internal_request feature and had a lot of issues getting it to work.

First, the documentation shows that Rodauth::Rails.rodauth should be used to make internal calls. However I figured out (from the tests) that it's actually RodauthApp.rodauth that should be used.

Also the usage of :env and alike is poorly explained. Again, according to the tests these should be added to the final call, like so: RodauthApp.rodauth.create_account(login: "user@example.com", password: "secret", env: env) while the docs make it look like it should be Rodauth::Rails.rodauth(env: env).create_account(login: "user@example.com", password: "secret").

Not sure if I just "read i wrong" but its confusing for sure.

janko commented 2 years ago

Thanks for the feedback. There is this part in the documentation:

If you need to access Rodauth methods not exposed as internal requests, you can use Rodauth::Rails.rodauth to retrieve the Rodauth instance used by the internal_request feature

But it's obviously confusing, as it may appear to someone scanning the code that this is how internal_request feature should be used. I think first showing an example of regular internal_request usage might make it clearer. The example with Rodauth::Rails.rodauth is really advanced usage if internal_request's class methods are not enough.

Bertg commented 2 years ago

Indeed, it skipped over the "normal" use case all together. Combined with the terse docs of rodauth it got very confusing. Only after reading the code did it finally click for me.