feat(auth): add email/password auth with JWT tokens#1
Merged
Conversation
Auth component (components/auth/): - User registration (POST /api/auth/register) with bcrypt password hashing - User login (POST /api/auth/login) returning signed JWT - Middleware() for protecting routes via Bearer token validation - Auto-creates users table (email UNIQUE, password_hash, created_at) - Auto-generates 256-bit JWT secret on first start (configurable) - Context timeout (5s) on all DB operations - MaxBytesReader (1MB) on request bodies Integrates with proxy: - /api/auth/ endpoints registered as public routes - /api/collections/ wrapped with auth middleware (JWT required) Dependencies: golang-jwt/jwt/v5, golang.org/x/crypto/bcrypt Tests: 13 tests covering register, login, duplicates, validation, middleware Defensive-code categories: Timeout (5s context deadline), Body limits (1MB)
- Extract decodeBody / writeAuthResponse to eliminate handler duplication - Replace magic number 1<<20 with maxBodyBytes constant - Add tests for ConfigSchema, Hooks, Version (coverage 75.8% → 80.0%) - Add ADR 002 documenting auth decisions (JWT, bcrypt, password policy, token expiry) Defensive-code categories: Body limits (named constant), Timeout (context deadline)
… context, coverage
Must-fix (3):
- Use res.LastInsertId() instead of separate SELECT with discarded error
- Normalize req.Email to lowercase early in both handlers
- Fix go.mod direct deps marked // indirect
Should-fix (5):
- Extract insertUser + hashPassword helpers to reduce handler length
- Tighten UNIQUE constraint detection ("UNIQUE constraint" substring)
- Handle rand.Read error in secret generation
- Verify registration succeeded before consuming token in tests
- Migrate middleware from HTTP headers to Go context.WithValue
Consider (5):
- Nil guard for Logger and DB in New
- Log JWT verification failures server-side
- Tests: case-insensitive email dedup, empty body, wrong method,
middleware empty Bearer prefix, context helpers for missing values
Coverage: 75.8% → 83.5%
Score: 38.5% → 100%
github-actions Bot
pushed a commit
that referenced
this pull request
Jun 1, 2026
# 1.0.0 (2026-06-01) ### Bug Fixes * address review findings — rows.Err, routing, YAML leak, repo filter ([45e79c3](45e79c3)) * address review findings — security, authz, race conditions ([2a49228](2a49228)) * **api db:** address all 18 code review findings ([9c693a4](9c693a4)) * **ci:** run smoke test binary with ./ prefix ([83b2de1](83b2de1)) * **deploy:** CI git safe.directory and Caddy http:// catch-all ([d0af465](d0af465)) * **deploy:** enable bigbase systemd unit on VPS setup ([2aa3361](2aa3361)) * **deploy:** resolve relative paths and URL update timing ([9ca144b](9ca144b)) * **deploy:** serve static files via HTTP file server ([575f780](575f780)) * **functions:** address review findings — interrupt timeout, validate update, runtime interface, body limit, injectable runtimes ([a45fa7a](a45fa7a)) * harden kernel, api, auth, forge, git, and storage components ([ef4ea80](ef4ea80)) * **realtime:** fix Hub data race, add event unsubscribe, log emit errors ([f10ed83](f10ed83)) * **ui:** export missing components from index.ts ([994bc53](994bc53)) ### Features * **admin-ui:** port Appwrite design tokens and create shared component system ([da3f118](da3f118)) * **admin:** add Admin UI, SQL Editor, and User Management ([e19e977](e19e977)) * **auth:** add email/password auth with JWT tokens ([#1](#1)) ([35c6096](35c6096)) * **auth:** add Google OAuth social login via embedded relay ([d4970ec](d4970ec)) * **cici:** add CI/CD pipeline component (Slice 9) ([5d2ba35](5d2ba35)) * **cli proxy kernel:** add CLI commands, proxy server, and observability ([fc23a09](fc23a09)) * **db api:** add SQLite database and auto REST CRUD API ([696befb](696befb)) * **deploy:** add deploy component with build detection, process execution, and port allocation ([c8d001a](c8d001a)) * **deploy:** improve deployment pipeline and add admin UI pages ([d056ce1](d056ce1)) * **forge:** add issues, labels, comments, kanban board, and wiki ([e893817](e893817)) * **functions:** add Functions component with CRUD operations ([00ea81c](00ea81c)) * **functions:** add goja JS runtime with console.log capture and timeout ([44a74f5](44a74f5)) * **functions:** wire Functions component into main.go ([9b89585](9b89585)) * **git:** add repository management with bare repo creation ([0481cfc](0481cfc)) * integrate semantic-release and display version in admin footer ([3e6b86c](3e6b86c)) * integrate semantic-release and display version in admin footer ([f042fe2](f042fe2)) * **messaging:** add email, SMS, and push notification endpoints with message log ([fd7cb61](fd7cb61)) * **messaging:** wire messaging component into main.go with auth middleware ([5e48755](5e48755)) * **monitoring:** add /api/monitoring/metrics endpoint with system and request metrics ([dcd0430](dcd0430)) * **monitoring:** add alert CRUD endpoints ([1b356e6](1b356e6)) * **monitoring:** add component shell with health endpoint ([b292c81](b292c81)) * **monitoring:** add log storage and search endpoints ([6d3a6b7](6d3a6b7)) * **monitoring:** add request metrics middleware ([4dfbbc1](4dfbbc1)) * **monitoring:** add system metrics collector ([fc6bd9e](fc6bd9e)) * **monitoring:** wire into main.go and add admin UI page ([0a683cd](0a683cd)) * **proxy:** add commercial landing page and documentation ([c3197e6](c3197e6)) * **proxy:** add commercial landing page with GitHub stars cache ([fea3761](fea3761)) * **proxy:** add documentation page with sidebar navigation ([dcaff68](dcaff68)) * **realtime:** add WebSocket subscriptions, event bus broadcasts, and Hub pattern ([4ab37bf](4ab37bf)) * **storage:** add file upload, download, list, and delete ([78ebe92](78ebe92)) * **ui:** enhance dashboard with charts and fix Google login visibility ([a453256](a453256)) ### BREAKING CHANGES * Deploy now triggers on release.published instead of every push to main.
|
🎉 This PR is included in version 1.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Auth component (Slice 4) with email/password registration, login, and JWT-based middleware for protecting API routes.
Changes
Details
golang.org/x/crypto(bcrypt),github.com/golang-jwt/jwt/v5/api/collections/routes;/api/auth/is publicKey design decisions