feat(auth): implement session-based authentication and API token management
- Introduced a new authentication system using session cookies for the web dashboard and API tokens for sync clients. - Replaced the old SERVER_PASSWORD scheme with a more secure API token mechanism. - Added routes for user setup, login, logout, and credential updates. - Implemented middleware to require session and API token for protected routes. - Updated web UI to handle authentication states and provide user feedback. - Enhanced error handling in API requests and responses. - Updated README to reflect new authentication flow and database requirements.
This commit is contained in:
1 parent
240e1fda4a
commit
b150d835a1
18 files changed
+1022
-982
No files matched your search
@@ -64,23 +64,18 @@ CollabTable allows multiple users to collaboratively create and manage lists wit
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
3. **Configure authentication (optional):**
|
||||
Edit `.env` and set `SERVER_PASSWORD` for API protection:
|
||||
```env
|
||||
SERVER_PASSWORD=your_secure_password
|
||||
```
|
||||
|
||||
4. **Start the server:**
|
||||
3. **Start the server (this also starts a bundled PostgreSQL container):**
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
Server runs on `http://localhost:3000`
|
||||
Server runs on `http://localhost:3000`. Open it in a browser to create the admin account,
|
||||
then generate an API token from the dashboard's Settings page for your sync clients/devices
|
||||
— see `CollabTableServer/README.md`'s "Authentication" section for details.
|
||||
|
||||
**Database Options:**
|
||||
- SQLite (default): Data persists in Docker volume `sqlite_data`
|
||||
- PostgreSQL: Configure in `.env` with `DB_CLIENT=postgres`
|
||||
**Database:** PostgreSQL, provisioned automatically via the bundled `postgres` service in
|
||||
`docker-compose.yml`.
|
||||
|
||||
### Android App
|
||||
|
||||
@@ -148,19 +143,19 @@ CollabTable/
|
||||
- **Runtime:** Node.js 20+
|
||||
- **Framework:** Express.js
|
||||
- **Language:** TypeScript
|
||||
- **Database:** SQLite (better-sqlite3) or PostgreSQL (pg)
|
||||
- **Database:** PostgreSQL (pg)
|
||||
- **Containerization:** Docker & Docker Compose
|
||||
- **Real-time:** WebSocket support
|
||||
|
||||
## API Endpoints
|
||||
|
||||
All endpoints are prefixed with `/api/` and can be protected with optional authentication.
|
||||
|
||||
### Authentication
|
||||
If `SERVER_PASSWORD` is set in the server's `.env` file, include this header in all requests:
|
||||
All endpoints are prefixed with `/api/`. The sync/collaboration endpoints below (Lists,
|
||||
Fields, Items, sync) require an API token generated from the web dashboard's Settings page:
|
||||
```
|
||||
Authorization: Bearer your_password_here
|
||||
Authorization: Bearer your_api_token_here
|
||||
```
|
||||
The dashboard itself has its own separate single-admin-account login (session cookie, not a
|
||||
bearer token) — see `CollabTableServer/README.md`'s "Authentication" section.
|
||||
|
||||
### Lists
|
||||
- `GET /api/lists` - Get all lists
|
||||
@@ -444,27 +439,10 @@ Response:
|
||||
|
||||
### Data Persistence
|
||||
|
||||
**SQLite (Default)**
|
||||
- Database stored in Docker volume: `sqlite_data`
|
||||
- Persists across container restarts
|
||||
- Backup database:
|
||||
```bash
|
||||
# Using container name (set in docker-compose.yml)
|
||||
docker cp collabtable-server:/data/collabtable.db ./backup.db
|
||||
|
||||
# Or using docker-compose (if in server directory)
|
||||
docker-compose exec server cat /data/collabtable.db > ./backup.db
|
||||
```
|
||||
- Restore database:
|
||||
```bash
|
||||
docker cp ./backup.db collabtable-server:/data/collabtable.db
|
||||
docker-compose restart
|
||||
```
|
||||
|
||||
**PostgreSQL**
|
||||
- Configure in `.env`: `DB_CLIENT=postgres`
|
||||
- Use standard PostgreSQL backup tools (`pg_dump`, `pg_restore`)
|
||||
- Docker volume manages persistence automatically
|
||||
- The bundled `postgres` service's data is stored in a named Docker volume (`pg_data`), which
|
||||
persists across container restarts
|
||||
|
||||
### Docker Commands
|
||||
|
||||
@@ -498,16 +476,15 @@ docker ps
|
||||
**Environment Variables**
|
||||
Configure these in `.env` or docker-compose.yml:
|
||||
```env
|
||||
PORT=3000 # Server port
|
||||
NODE_ENV=production # Environment
|
||||
SERVER_PASSWORD=your_secure_pass # API authentication (recommended)
|
||||
DB_CLIENT=sqlite # Database: sqlite or postgres
|
||||
DB_PATH=/data/collabtable.db # SQLite path (in container)
|
||||
PORT=3000 # Server port
|
||||
NODE_ENV=production # Environment
|
||||
DATABASE_URL=postgres://user:pass@postgres:5432/collabtable
|
||||
COOKIE_SECURE=true # Requires HTTPS
|
||||
```
|
||||
|
||||
**Security Recommendations**
|
||||
1. Set `SERVER_PASSWORD` for production
|
||||
2. Use HTTPS with a reverse proxy (nginx, Caddy)
|
||||
1. Generate the admin account and an API token on first run (see "Authentication" above)
|
||||
2. Use HTTPS with a reverse proxy (nginx, Caddy), and set `COOKIE_SECURE=true`
|
||||
3. Regular database backups
|
||||
4. Keep Docker images updated
|
||||
5. Restrict network access to server ports
|
||||
|
||||
Reference in new issue
Block a user