One-file FastAPI authentication system with JWT tokens, user management, admin panel, and built-in frontend.
pip install -r requirements.txt
python main.py
# Open http://localhost:8080| Variable | Default | Description |
|---|---|---|
SECRET_KEY |
auto-generated | JWT signing key (set for persistence across redeploys) |
ACCESS_TOKEN_EXPIRE_MINUTES |
30 |
Access token lifetime |
REFRESH_TOKEN_EXPIRE_DAYS |
7 |
Refresh token lifetime |
APP_NAME |
FastAPI Auth |
Shown in UI |
- To create the one-click deploy template: Railway Dashboard β Project β Settings β Generate Template
- Register / Login (email or username) / Logout
- JWT access + refresh tokens with rotation
- Token revocation (logout invalidates tokens)
- Profile view & edit, password change, account deletion
- Admin panel: list users, toggle active/admin status
- Auto-creates tables on startup
- SQLite locally, PostgreSQL on Railway
- Built-in frontend + Swagger UI at
/docs
POST /api/auth/register β Create account, get tokens
POST /api/auth/login β Login, get tokens
POST /api/auth/refresh β Rotate refresh token
POST /api/auth/logout β Revoke token
GET /api/users/me β Get profile
PATCH /api/users/me β Update profile
POST /api/users/me/change-password
DELETE /api/users/me β Delete account
GET /api/admin/users β List all users (admin)
PATCH /api/admin/users/{id}/toggle-active
PATCH /api/admin/users/{id}/toggle-admin
GET /api/health
Register your first user via the UI, then connect to the Railway PostgreSQL and run:
UPDATE users SET is_admin = true WHERE id = 1;