3.1 KiB
3.1 KiB
RedFlag Admin Login Fix - COMPLETED ✓
Final Status: SUCCESS
Login now works! The admin can successfully authenticate and receive a JWT token.
Root Cause
The Admin struct had ID int64 but the database uses UUID type, causing a type mismatch during SQL scanning which prevented proper password verification.
What Was Fixed
1. Column name mismatches in admin.go
Fixed all SQL queries to match the database schema (migration 001):
CreateAdminIfNotExists: Removed non-existentupdated_atcolumn from INSERTUpdateAdminPassword: Changedpassword→password_hash, removedupdated_atVerifyAdminCredentials: Changedpassword→password_hash, removedupdated_atGetAdminByUsername: Removedupdated_atfrom SELECT
2. Type mismatch in Admin struct
- Changed
IDfield fromint64touuid.UUIDto match database - Added
github.com/google/uuidimport - Removed
UpdatedAtfield (doesn't exist in database)
3. Execution order fix
- Admin creation now happens AFTER
isSetupComplete()validation - Prevents creating admin with incomplete configuration
4. Docker-compose fix
- Removed hardcoded postgres credentials that were overriding .env values
Testing Results
$ curl -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"Qu@ntum21!"}'
Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "b0ea99d0-e3ce-40cd-a510-1fb56072646a",
"username": "admin",
"email": "",
"created_at": "2025-12-15T03:10:53.38145Z"
}
}
HTTP Status: 200
What to Test Next
-
Use the JWT token to access protected endpoints:
curl -H "Authorization: Bearer <token>" http://localhost:8080/api/v1/stats/summary -
Verify the web dashboard loads and works with the token
-
Test admin password sync: Change password in config/.env and restart to verify it updates
Quick Reference Commands
# View logs
docker compose logs server --tail=50
# Stream logs
docker compose logs server -f
# Check database
docker compose exec postgres psql -U redflag -d redflag -c "SELECT * FROM users;"
# Test login
curl -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"Qu@ntum21!"}'
# Restart after code changes
docker compose build server && docker compose up -d --force-recreate server
# Full restart (if needed)
docker compose down && docker compose up -d
Files Modified
aggregator-server/internal/database/queries/admin.go- Fixed SQL queries and Admin structdocker-compose.yml- Removed hardcoded postgres credentials
Current Database Schema (users table)
id UUID PRIMARY KEY
db_username VARCHAR(255) UNIQUE
email VARCHAR(255) UNIQUE
password_hash VARCHAR(255)
role VARCHAR(50)
created_at TIMESTAMP
last_login TIMESTAMP
Notes
- The .env has two
REDFLAG_SIGNING_PRIVATE_KEYentries (second overwrites first) - Admin creation only runs when all setup validation passes
- Password is synced from .env on every startup (UpdateAdminPassword function)