Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support --live to phx.gen.auth #4872

Merged
merged 58 commits into from
Aug 1, 2022
Merged

Support --live to phx.gen.auth #4872

merged 58 commits into from
Aug 1, 2022

Conversation

bemesa21
Copy link
Contributor

@bemesa21 bemesa21 commented Jun 23, 2022

Added --live option to phx.gen.auth command.
With this new option, in addition to generating an authentication system with Phoenix.Views, you can also generate an authentication system using LiveViews.

To generate an authentication system, the following options can be used:

  • --live to generate a system with LiveView
  • --no-live to generate a system with Phoenix.View

Additionally, if neither of these options is given, a prompt will be displayed so that the user can choose between these two options.

TODO

  • Add interactive Y/n prompt for LiveView generation on mix phx.gen.auth if --live and --no-live is not present

@bemesa21 bemesa21 linked an issue Jun 23, 2022 that may be closed by this pull request
@chvanikoff
Copy link
Contributor

Thanks for the amazing work!

I've tested it a little and found a couple of small issues (besides a few typos above) in registration flow. Let me know if you want any help with it, I'll be happy to dig into the issues and contribute.

  1. Errors are not live, so you have to submit the form before you see any
  2. DB is queried to validate email uniqueness even when password field is being edited
  3. On successful registration user is redirected to login page with "login failed" flash message

@bemesa21
Copy link
Contributor Author

Thanks for the feedback @chvanikoff!

I'll take a look to the live errors, I'll change how email and password are validated.

In the case of the third point, I noticed that issue and asked Chris for help, but I still don't know what's going on and why the unit test I wrote doesn't show that error.

What I've found so far is that when the parameters get to the session controller action, the password is an empty string.

It would be very helpful if we can find out why this behavior happens.

@chvanikoff
Copy link
Contributor

Just realised SettingsController is not ported to LiveView yet - Is it WIP, forgotten, not meant to be part of the PR, or not meant to be ported at all? :)

@bemesa21
Copy link
Contributor Author

@chvanikoff the SettingsController and the ConfirmationController were missing, I wasn't sure if we planned to create those LiveView as well. But now they are part of this PR! 😃

lib/mix/phoenix/schema.ex Outdated Show resolved Hide resolved
id="login_form"
:let={f}
for={:<%= schema.singular %>}
phx-change="validate"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove validate. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self, removing validate is pending on me with a new LV feature that maintains form state in the event of phx-change absence

Copy link
Member

@connorlay connorlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, I'm looking forward to having this available for new apps 😄

I'm wondering if mix phx.gen.auth --live should generate a live session in the router for the authenticated routes so we can use live navigation? That will expose new users to that concept early in the app's development.

router_scope: router_scope(context),
web_path_prefix: web_path_prefix(schema),
test_case_options: test_case_options(ecto_adapter)
test_case_options: test_case_options(ecto_adapter),
live?: Keyword.fetch!(context.opts, :live)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to document this new flag above in the @moduledoc? That way it should appear as an option when one runs mix help phx.gen.auth.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just documented it here: #5261

priv/templates/phx.gen.auth/registration_live.ex Outdated Show resolved Hide resolved
priv/templates/phx.gen.auth/settings_live.ex Show resolved Hide resolved
for={@password_changeset}
action={Routes.<%= schema.route_helper %>_session_path(@socket, :create, %{_action: "password_updated"})}
method="post"
phx-change="validate_password"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like I can update my password using the exact value of my current password. Is that something we should prevent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support --live to phx.gen.auth
7 participants