Caravela.Gen.Auth (Caravela v0.12.0)

Copy Markdown View Source

Generates the authentication stack for a Caravela.Schema.Domain whose authenticatable entity declares an authenticatable block.

Emits:

  • lib/<app>/<context>/auth.ex — auth context (register, login, logout, sessions, API tokens, reset, confirm)
  • lib/<app>/<context>/user_session.ex — session schema
  • lib/<web>/plugs/auth.ex — plug pipeline
  • lib/<web>/live/auth_hooks.ex — LiveView on_mount hooks
  • lib/<web>/controllers/auth_controller.ex — auth endpoints
  • priv/repo/migrations/<ts>_create_<context>_user_sessions.exs — session tokens migration

Returns a list of {path, source} tuples — the caller writes files. Files preserve content below the # --- CUSTOM --- marker on regeneration. The session migration is never merged (no marker) and is timestamped like any other migration.

Summary

Functions

Render all auth files. Raises if the domain has no authenticatable entity.

Render the auth context module.

Render the auth HTTP controller.

Render the LiveView on_mount hooks module.

Render the session-tokens migration file.

Render the Plug pipeline module.

Render the session schema module.

Return a ready-to-paste router snippet showing the public auth routes, protected live_session, and authenticated API scope. Printed by mix caravela.gen.auth after writing files.

Functions

render_all(domain, opts \\ [])

Render all auth files. Raises if the domain has no authenticatable entity.

Options:

  • :root — project root, used to resolve existing files for custom-block preservation (defaults to File.cwd!())
  • :timestamp — pin the migration timestamp (useful for tests)

render_context(domain, opts \\ [])

Render the auth context module.

render_controller(domain, opts \\ [])

Render the auth HTTP controller.

render_live_hooks(domain, opts \\ [])

Render the LiveView on_mount hooks module.

render_migration(domain, opts \\ [])

Render the session-tokens migration file.

render_plugs(domain, opts \\ [])

Render the Plug pipeline module.

render_session_schema(domain, opts \\ [])

Render the session schema module.

router_snippet(domain)

Return a ready-to-paste router snippet showing the public auth routes, protected live_session, and authenticated API scope. Printed by mix caravela.gen.auth after writing files.