View Source mix phx.gen.auth (Phoenix v1.7.11)
Generates authentication logic and related views for a resource.
$ mix phx.gen.auth Accounts User users
The first argument is the context module followed by the schema module and its plural name (used as the schema table name).
Additional information and security considerations are detailed in the
mix phx.gen.auth guide.
Authentication views can either be generated to use LiveView by passing
--live option, or they can use conventional Phoenix
Controllers & Views by passing
If neither of these options are provided, a prompt will be displayed.
--live option is advised if you plan on using LiveView
elsewhere in your application. The user experience when navigating between
LiveViews can be tightly controlled, allowing you to let your users navigate
to authentication views without necessarily triggering a new HTTP request
each time (which would result in a full page load).
The password hashing mechanism defaults to
Unix systems and
pbkdf2 for Windows systems. Both
systems use the Comeonin interface.
The password hashing mechanism can be overridden with the
--hashing-lib option. The following values are supported:
We recommend developers to consider using
is the most robust of all 3. The downside is that
is quite CPU and memory intensive, and you will need more
powerful instances to run your applications on.
For more information about choosing these libraries, see the Comeonin project.
By default, the controllers and HTML view will be namespaced by the schema name.
You can customize the web module namespace by passing the
--web flag with a
module name, for example:
$ mix phx.gen.auth Accounts User users --web Warehouse
Which would generate the controllers, views, templates and associated tests nested in the
- and so on...
You can invoke this generator multiple times. This is typically useful if you have distinct resources that go through distinct authentication workflows:
$ mix phx.gen.auth Store User users
$ mix phx.gen.auth Backoffice Admin admins
--binary-id option causes the generated migration to use
binary_id for its primary key and foreign keys.
This generator uses default options provided in the
configuration of your application. These are the defaults:
config :your_app, :generators,
You can override those options per invocation by providing corresponding
--no-binary-id to use normal ids despite the default
By default, the table name for the migration and schema will be
the plural name provided for the resource. To customize this value,
--table option may be provided. For example:
$ mix phx.gen.auth Accounts User users --table accounts_users
This will cause the generated tables to be named