feat(lvt): redesign gen auth for LiveTemplate v0.5.1#5
Conversation
Migrate `lvt gen auth` from v0.4.x workaround patterns to new v0.5.1 ActionContext HTTP APIs. Password auth is now enabled by default. **Changes:** 1. **Auth Handler Template** (handler.go.tmpl) - Remove manual ResponseWriter/Request extraction - Use ctx.SetCookie() instead of http.SetCookie(s.httpWriter, ...) - Use ctx.Redirect() instead of http.Redirect(s.httpWriter, s.httpRequest, ...) - Remove httpWriter and httpRequest fields from AuthState 2. **Re-enable Password Auth** (auth.go) - Remove outdated v0.4.x compatibility warning - Password authentication enabled by default 3. **Documentation** (SKILL.md) - Add comprehensive LiveTemplate v0.5.1+ HTTP APIs section - Document SetCookie, GetCookie, DeleteCookie, Redirect APIs - Add security best practices and error handling examples 4. **Tests** (auth_test.go) - Update comment about password.go generation - Add password.go to expected generated files **Benefits:** - Modern, clean ActionContext API usage - Built-in redirect validation and cookie security - Better developer experience with password auth working out-of-box - Clear documentation of v0.5.1 capabilities All auth tests passing ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Pull Request Review: Migrate
|
There was a problem hiding this comment.
Pull request overview
This PR migrates the lvt gen auth command from v0.4.x workaround patterns to LiveTemplate v0.5.1's native ActionContext HTTP APIs. The changes enable password authentication by default and modernize the generated auth code to use clean, built-in methods for cookies and redirects instead of manual ResponseWriter/Request extraction.
Key changes:
- Auth handler template now uses
ctx.SetCookie()andctx.Redirect()instead of manual HTTP operations - Password authentication re-enabled by default (removed temporary v0.4.x compatibility warning)
- Comprehensive documentation added for all v0.5.1 HTTP APIs with security best practices
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
internal/kits/system/multi/templates/auth/handler.go.tmpl |
Migrated handleLogin to use ActionContext HTTP APIs; removed httpWriter/httpRequest state fields |
commands/auth.go |
Removed v0.4.x compatibility warning and forced password auth disabling |
commands/auth_test.go |
Updated test expectations to include password.go in generated files |
commands/claude_resources/skills/gen-auth/SKILL.md |
Added comprehensive documentation for v0.5.1 HTTP APIs with security best practices and error handling examples |
Summary
Migrate
lvt gen authfrom v0.4.x workaround patterns to new v0.5.1 ActionContext HTTP APIs. Password auth is now enabled by default and uses modern, clean API patterns.Changes
1. Auth Handler Template (
handler.go.tmpl)ctx.SetCookie()instead ofhttp.SetCookie(s.httpWriter, ...)ctx.Redirect()instead ofhttp.Redirect(s.httpWriter, s.httpRequest, ...)httpWriterandhttpRequestfields from AuthState2. Re-enable Password Auth (
auth.go)3. Documentation (
SKILL.md)SetCookie(),GetCookie(),DeleteCookie()Redirect(),SetHeader(),GetHeader(),IsHTTP()4. Tests (
auth_test.go)internal/shared/password/password.goto expected generated filesBenefits
✨ Modern API Usage: Generated auth code uses clean ActionContext HTTP methods instead of workarounds
🔒 Security: Built-in redirect validation (prevents open redirects) and proper cookie security flags
🎯 Developer Experience: Password auth works out-of-the-box, no more confusing warnings
📚 Documentation: Clear examples of all v0.5.1 HTTP capabilities
Test Results
All auth-related tests passing:
Generated Files Verified
internal/app/auth/auth.go(with v0.5.1 APIs)internal/shared/password/password.go(now generated by default)internal/shared/email/email.gointernal/database/migrations/*_create_auth_tables.sqlBreaking Changes
None - this is backward compatible. Apps using the generated code will automatically benefit from the new APIs when they upgrade to livetemplate v0.5.1+.
Related