Why does phx_gen_auth put `user_auth.ex` into "controllers" directory?

Is there some strong rationale behind this choice? I mean something like “that’s the right place for it because […]” Or was it more like “there is no right place for it so it might just sit along with the controllers”?

1 Like

Doesn’t it put it under /controllers/<context_name>/user_auth.ex? In that case I wouldn’t consider it as “into controllers” but as a “private” helper module for <context_name>_controller

Hm… Now I don’t recall how exactly I invoked the generator (and history’s no longer valid) but what I got is:

Screenshot 2021-08-11 at 10.21.33

It puts it in controllers/user_auth.ex indeed. Those are exclusively controller helpers, so that’s the directory it should go to.


If it would be inline with the one existing helper module (views/error_helpers.ex) then it would be controllers/user_auth_helpers.ex though.


IMHO too that would be more consistent and understandable. Not that it’s a huge deal but a bit more consistent conventions around Phoenix wouldn’t hurt (again IMHO, while still having relatively fresh eye on it).

I felt the same personally, so I pulled helpers out to a separate directory

Web.Helpers.UserAuth, Web.Helpers.HTML, etc

1 Like