Spaces:
Sleeping
Sleeping
README translated to English
Browse files
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title: Planner Auth —
|
| 3 |
emoji: 🔐
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: green
|
|
@@ -11,48 +11,48 @@ license: mit
|
|
| 11 |
|
| 12 |
# Planner Auth 🔐
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
##
|
| 17 |
|
| 18 |
-
1.
|
| 19 |
-
2.
|
| 20 |
-
3.
|
| 21 |
-
4.
|
| 22 |
|
| 23 |
## Endpoints
|
| 24 |
|
| 25 |
-
###
|
| 26 |
-
|
|
| 27 |
|---|---|
|
| 28 |
-
| `POST /api/register` |
|
| 29 |
-
| `POST /api/login` | bcrypt compare, **
|
| 30 |
-
| `POST /api/logout` |
|
| 31 |
-
| `GET /api/me` |
|
| 32 |
-
| `POST /api/forgot-password` |
|
| 33 |
-
| `POST /api/reset-password` |
|
| 34 |
-
|
| 35 |
-
###
|
| 36 |
-
|
|
| 37 |
|---|---|
|
| 38 |
-
| `GET/POST /api/habits`, `PUT/DELETE /api/habits/:id` |
|
| 39 |
-
| `GET /api/checkins`, `POST /api/checkins/toggle` |
|
| 40 |
-
| `GET/POST /api/tasks`, `PUT/DELETE /api/tasks/:id`, `POST /api/tasks/reorder` |
|
| 41 |
-
| `GET/POST /api/sessions` |
|
| 42 |
-
| `GET /app` |
|
| 43 |
-
|
| 44 |
-
##
|
| 45 |
-
|
| 46 |
-
- **bcrypt**
|
| 47 |
-
- **
|
| 48 |
-
- **
|
| 49 |
-
- **`/app`
|
| 50 |
-
- **
|
| 51 |
-
- **
|
| 52 |
-
|
| 53 |
-
##
|
| 54 |
-
|
| 55 |
-
-
|
| 56 |
-
-
|
| 57 |
-
-
|
| 58 |
-
-
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Planner Auth — Real Authentication
|
| 3 |
emoji: 🔐
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: green
|
|
|
|
| 11 |
|
| 12 |
# Planner Auth 🔐
|
| 13 |
|
| 14 |
+
A **real (server-side) authentication server** **+ protected planner**: passwords hashed with bcrypt, sessions managed by the server with an `httpOnly` cookie, each user's data stored and filtered **on the server**, and an `/app` page that only opens with a valid session.
|
| 15 |
|
| 16 |
+
## How to use it
|
| 17 |
|
| 18 |
+
1. Open the Space → **Sign up** → create an account → click **Open the Planner**.
|
| 19 |
+
2. The planner (`/app`) loads habits, tasks and focus sessions **from the server API** — nothing in IndexedDB.
|
| 20 |
+
3. Try opening `/app` while logged out: the server redirects you to the login.
|
| 21 |
+
4. Reload the page: you're still logged in (the session lives on the server).
|
| 22 |
|
| 23 |
## Endpoints
|
| 24 |
|
| 25 |
+
### Authentication
|
| 26 |
+
| Route | What it does |
|
| 27 |
|---|---|
|
| 28 |
+
| `POST /api/register` | validates, hashes with bcrypt (10 rounds), creates the user, starts a session |
|
| 29 |
+
| `POST /api/login` | bcrypt compare, **regenerates the session** (anti fixation), rate limit of 5 tries / 15 min |
|
| 30 |
+
| `POST /api/logout` | destroys the session on the server |
|
| 31 |
+
| `GET /api/me` | protected — returns the session's user, or 401 |
|
| 32 |
+
| `POST /api/forgot-password` | random token, stored only as a SHA-256 hash, 15 min validity |
|
| 33 |
+
| `POST /api/reset-password` | validates the token (single use) and replaces the password hash |
|
| 34 |
+
|
| 35 |
+
### Per-user data — all require a session and filter by `owner`
|
| 36 |
+
| Route | What it does |
|
| 37 |
|---|---|
|
| 38 |
+
| `GET/POST /api/habits`, `PUT/DELETE /api/habits/:id` | the logged-in user's habits (emoji, color, daily/weekly with a goal) |
|
| 39 |
+
| `GET /api/checkins`, `POST /api/checkins/toggle` | daily completions (`{habitId, date}`), validates habit ownership |
|
| 40 |
+
| `GET/POST /api/tasks`, `PUT/DELETE /api/tasks/:id`, `POST /api/tasks/reorder` | tasks with priority and due date, reordering by id list |
|
| 41 |
+
| `GET/POST /api/sessions` | focus (pomodoro) sessions |
|
| 42 |
+
| `GET /app` | the planner page — **redirects to `/` without a session** |
|
| 43 |
+
|
| 44 |
+
## Security details
|
| 45 |
+
|
| 46 |
+
- **bcrypt** with 10 rounds — the password is never stored as plain text.
|
| 47 |
+
- **Server-side session**: the `planner.sid` cookie is `httpOnly`, `sameSite=lax`, automatically `Secure` behind the Space's HTTPS; secret generated with `crypto.randomBytes` and persisted.
|
| 48 |
+
- **Session regeneration on login** (anti fixation) and login rate limiting.
|
| 49 |
+
- **`/app` outside `express.static`**: the file lives in `private/` and is only served by the route that requires a session — there is no way to download it directly.
|
| 50 |
+
- **Per-user isolation on the server**: every data route filters by `owner = current session`; a user cannot read or change another user's data, even by forging ids.
|
| 51 |
+
- **Reset token** stored as a SHA-256 hash, single use, expiring; the "forgot password" response is identical whether the e-mail exists or not.
|
| 52 |
+
|
| 53 |
+
## Honest limitations
|
| 54 |
+
|
| 55 |
+
- Storage is `data/db.json` (swap for SQLite/Postgres in production).
|
| 56 |
+
- Sessions are in memory (`MemoryStore`) — they don't survive a Space restart; use Redis in production.
|
| 57 |
+
- No e-mail in a Space: the reset token comes back in the API response (demo). In production it would go by e-mail.
|
| 58 |
+
- No explicit CSRF token (`sameSite=lax` covers the basic case); no HTTPS of its own (the Space proxy handles it).
|