Skip to content

Add winn create auth scaffold + auth guide (#168)#182

Merged
gregwinn merged 1 commit into
developfrom
feature/auth-scaffold
Jun 13, 2026
Merged

Add winn create auth scaffold + auth guide (#168)#182
gregwinn merged 1 commit into
developfrom
feature/auth-scaffold

Conversation

@gregwinn

Copy link
Copy Markdown
Owner

Summary

The final piece of the authentication epic (#161): winn create auth scaffolds a complete email/password setup in one command, plus a full docs/auth.md guide. Branched off develop.

winn create auth
#   create  src/models/user.winn
#   create  src/models/auth_token.winn
#   create  db/migrations/<ts>01_create_users.winn
#   create  db/migrations/<ts>02_create_auth_tokens.winn
#   create  src/controllers/auth_controller.winn

The generated AuthController wires all eight endpoints (register / login / refresh / logout / verify / forgot / reset / me) with [:cors, :auth] middleware and an exclude list; the migrations are ordered (01/02) with proper constraints.

Details

  • winn_generator: generate(auth, _) + dedicated templates; winn_cli: create auth dispatch + help text.
  • Caught a pre-existing bug: the existing model_template emits quoted struct atoms (struct [:"email"]) that don't parse — so winn create model currently generates non-compiling models. The auth scaffold uses a schema-only template that compiles. (Worth a follow-up issue for create model.)
  • Fixed non-compiling docs: %{ok: true} in docs/modules.mdok/err are reserved and can't be map keys (verified it's a parse error); changed to %{status: "ok"}.
  • docs/auth.md: end-to-end guide — quick start, token model, a runnable JS frontend example (with silent refresh), cookie mode, account recovery, security notes. docs/cli.md + docs/roadmap.md updated.

Testing

New winn_auth_scaffold_tests runs the generator in a temp dir and compiles the output: the controller compiles + loads with 8 routes and [cors, auth] middleware + an exclude config; both models compile (compiled-not-loaded, so the user beam doesn't clobber OTP's user module). Also verified winn create auth end-to-end via the built escript. Full suite 769, only the pre-existing winn_sqlite_tests esqlite-NIF failure.

Part of #161. Closes #168. This completes the authentication epic — Phases 1–4 all done.

🤖 Generated with Claude Code

Final piece of the auth epic (#161): one command scaffolds a complete
email/password setup, plus an end-to-end guide.

- winn_generator: generate(auth, _) writes User + AuthToken schemas, ordered
  users/auth_tokens migrations (with constraints), and an AuthController router
  wiring all eight endpoints (register/login/refresh/logout/verify/forgot/reset/me)
  with [:cors, :auth] middleware + exclude list. winn_cli: `create auth` dispatch
  + help text.
- Generated models use a schema-only template: the existing model_template emits
  quoted struct atoms (struct [:"email"]) that don't parse — pre-existing bug in
  `winn create model`, avoided here.
- docs/auth.md: full guide (token model, Bearer vs cookie, account recovery, a
  runnable JS frontend example). docs/cli.md + roadmap updated.
- Fixed `%{ok: true}` examples in docs/modules.md — ok/err are reserved and can't
  be map keys (confirmed it's a parse error); use `%{status: "ok"}`.
- New winn_auth_scaffold_tests runs the generator in a temp dir and compiles the
  output (controller has 8 routes + [cors,auth]; models compile). Full suite 769
  (only the pre-existing esqlite-NIF failure).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gregwinn gregwinn added this to the v1.0.0 — The Winn Platform milestone Jun 13, 2026
@gregwinn gregwinn added documentation Improvements or additions to documentation enhancement New feature or request area/cli CLI commands (winn_cli.erl) labels Jun 13, 2026
@gregwinn gregwinn merged commit 5b59ef9 into develop Jun 13, 2026
2 checks passed
@gregwinn gregwinn deleted the feature/auth-scaffold branch June 13, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli CLI commands (winn_cli.erl) documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant