PhxAuthPlus

View Source

Complete email + password authentication generator for Phoenix 1.8+.

Phoenix 1.8 replaced mix phx.gen.auth with a magic-link-only generator. PhxAuthPlus restores the full email + password experience — registration, login, password reset, account confirmation, "remember me", and settings — while using modern Igniter-based code generation.

Installation

Add to your mix.exs:

def deps do
  [
    {:phx_auth_plus, "~> 0.1", only: [:dev, :test]}
  ]
end

Then:

mix deps.get
mix phx_auth_plus.gen.auth Accounts User users

The generator adds the hashing library dependency, configures the test environment, generates all auth files, and updates your layout and router.

Quick start

# Generate auth (LiveView UI, bcrypt on Unix / pbkdf2 on Windows)
mix phx_auth_plus.gen.auth Accounts User users

# Then:
mix ecto.migrate
mix phx.server

Visit http://localhost:4000/users/register.

Generated features

FeatureDescription
RegistrationEmail + password signup with validation
Login / LogoutSession-based with "remember me" cookie
Password resetForgot password flow with email token
Account confirmationEmail verification with token
SettingsChange password and email (with confirmation)
Session trackingAll sessions stored in DB, invalidated on password change
Auth testsGenerated test suite for UserAuth plug and hooks

Usage

# Default: LiveView UI, bcrypt on Unix / pbkdf2 on Windows
mix phx_auth_plus.gen.auth Accounts User users

# Controller-only UI (no LiveView)
mix phx_auth_plus.gen.auth Accounts User users --no-live

# Use argon2 hashing
mix phx_auth_plus.gen.auth Accounts User users --hashing-lib argon2

# Use binary UUID keys
mix phx_auth_plus.gen.auth Accounts User users --binary-id

# Custom table name
mix phx_auth_plus.gen.auth Accounts User users --table app_users

# Custom web module
mix phx_auth_plus.gen.auth Accounts User users --web MyAppWeb

Options

OptionDefaultDescription
--hashing-libbcrypt (Unix) / pbkdf2 (Windows)Password hashing library
--livetrueGenerate LiveView auth pages
--no-liveGenerate controller-based auth pages
--binary-idfalseUse binary UUID primary keys
--webMyAppWebWeb module name
--context-appapp nameContext app (umbrella projects)
--tableplural argDatabase table name

Generated files

lib/my_app/accounts/
 user.ex              # User schema with changesets
 user_token.ex        # Token schema (session, reset, confirm, change email)
 user_notifier.ex     # Email notification delivery (Swoosh)

lib/my_app_web/
 user_auth.ex         # Auth plug + LiveView hooks

# With --live (default):
 user_*_live.ex       # Login, registration, settings, forgot/reset, confirmation

# With --no-live:
 controllers/
     user_*_controller.ex

priv/repo/migrations/
 *_create_users_auth_tables.exs

test/
 support/accounts_fixtures.ex    # Test fixtures
 *_user_auth_test.exs            # UserAuth tests

Routes

PathMethodDescription
/users/registerGET/POSTRegistration
/users/log_inGET/POSTLogin
/users/log_outDELETELogout
/users/reset_passwordGET/POSTRequest password reset
/users/reset_password/:tokenGET/PUTReset password with token
/users/confirmGET/POSTResend confirmation
/users/confirm/:tokenGETConfirm account
/users/settingsGET/PUTSettings (auth required)
/users/settings/confirm_email/:tokenGETConfirm email change

Token validity

Token typeContextValidity
Sessionsession60 days
Reset passwordreset_password1 day
Confirm accountconfirm7 days
Change emailchange:{old_email}7 days

Email delivery

The generated UserNotifier uses Swoosh to build emails. In development, the local adapter captures emails at /dev/mailbox.

To send real emails, configure a Swoosh adapter in config/runtime.exs. See the GUIDE for details.

Customization

See the GUIDE.md for:

  • Adding custom fields to User
  • Role-based authorization
  • Configuring the mailer for production
  • Changing password requirements
  • Disabling account confirmation
  • Using API tokens
  • Umbrella project support

vs Phoenix 1.8 built-in auth

FeaturePhoenix 1.8PhxAuthPlus
Email + passwordMagic links onlyFull support
Password resetMagic links onlyToken-based reset
Account confirmationNot includedEmail confirmation
"Remember me"Not includedSecure cookies
Settings pageNot includedChange email + password
Session trackingNot includedDB-tracked sessions
Code generationManualIgniter-based (AST)

Roadmap

v0.2.0 (planned)

  • Generated LiveView tests (registration, login, settings flows)
  • --no-confirm flag to skip account confirmation

v0.3.0 (planned)

  • OAuth 2.0 provider support (Google, GitHub)
  • API token authentication

v1.0.0 (future)

  • Two-factor authentication (TOTP)
  • Session management UI (view/revoke active sessions)

License

MIT