phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.23k stars 2.86k forks source link

mix gen.auth creates live views in parent folder instead of using its own like the other #5869

Open ponychicken opened 2 months ago

ponychicken commented 2 months ago

Environment

Actual behavior

When using mix gen.auth it polutes the live folder instead of putting its files into a seperate one, like all the other gen tools do.

$ mix phx.new test $ mix phx.gen.live TestObject [...] $ mix phx.gen.auth Access User users

➜ test_web tree

.
├── components
│   ├── core_components.ex
│   ├── layouts
│   │   ├── app.html.heex
│   │   └── root.html.heex
│   └── layouts.ex
├── controllers
│   ├── error_html.ex
│   ├── error_json.ex
│   ├── page_controller.ex
│   ├── page_html
│   │   └── home.html.heex
│   ├── page_html.ex
│   └── user_session_controller.ex
├── endpoint.ex
├── gettext.ex
├── live
│   ├── other_object_live
│   │   ├── form_component.ex
│   │   ├── index.ex
│   │   ├── index.html.heex
│   │   ├── show.ex
│   │   └── show.html.heex
│   ├── test_object_live
│   │   ├── form_component.ex
│   │   ├── index.ex
│   │   ├── index.html.heex
│   │   ├── show.ex
│   │   └── show.html.heex
│   ├── user_confirmation_instructions_live.ex
│   ├── user_confirmation_live.ex
│   ├── user_forgot_password_live.ex
│   ├── user_login_live.ex
│   ├── user_registration_live.ex
│   ├── user_reset_password_live.ex
│   └── user_settings_live.ex
├── router.ex
├── telemetry.ex
└── user_auth.ex

Expected behavior

Use a seperate folder

rhcarvalho commented 1 month ago

I think that's by design. The code in test_object_live and other_object_live are variations of the same page, CRUD for a single entity. On the other hand, those user_*_live.ex are conceptually different.

They could be grouped into a common directory, but no sure what improvement it would make in practice. Or even how to name such directory?!

Maybe some git-archeology can help us understand how it came to be, or maybe someone on the Phoenix team is quick at clarifying it :)

ponychicken commented 1 month ago

In the end the users are just another data point in the DB. Right now it doesn't come with a view to list all users but that view would be conceptually the same as listing all items of another object.

Regarding naming, i think it would be straighforward to use the passed context attribute (accounts in the example)

ponychicken commented 1 month ago

It also states quite clearly in the docs itself: The mix phx.gen.auth generator is similar to mix phx.gen.html except it does not accept a list of additional fields to add to the schema, and it generates many more context functions.

josevalim commented 1 month ago

The docs are meant to say it is similar in the arguments, but not necessarily in all of its outputs (which cannot be true).

If we wanted though, we could namespace all of those under the user_live folder. So we have, UserLive.Login, and so on. It feels this would make it more consistent.