Offlin33er commited on
Commit
907c7ec
·
verified ·
1 Parent(s): d04a15c

README translated to English

Browse files
Files changed (1) hide show
  1. README.md +39 -39
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Planner Auth — Autenticação real
3
  emoji: 🔐
4
  colorFrom: indigo
5
  colorTo: green
@@ -11,48 +11,48 @@ license: mit
11
 
12
  # Planner Auth 🔐
13
 
14
- Servidor de **autenticação real** (não client-side) **+ planner protegido**: senhas com hash bcrypt, sessões gerenciadas pelo servidor com cookie `httpOnly`, dados de cada usuário guardados e filtrados **no servidor**, e uma página `/app` que só abre com sessão válida.
15
 
16
- ## Fluxo de uso
17
 
18
- 1. Abra o Space → **Cadastro** → crie a conta → botão **Abrir o Planner**.
19
- 2. O Planner (`/app`) carrega hábitos, tarefas e foco **da API do servidor** — nada em IndexedDB.
20
- 3. Tente abrir `/app` sem estar logado: o servidor redireciona para o login.
21
- 4. Recarregue a página: você continua logado (sessão no servidor).
22
 
23
  ## Endpoints
24
 
25
- ### Autenticação
26
- | Rota | O que faz |
27
  |---|---|
28
- | `POST /api/register` | valida, gera hash bcrypt (10 rounds), cria usuário, inicia sessão |
29
- | `POST /api/login` | bcrypt compare, **regenera a sessão** (anti fixação), rate limit 5 tent./15 min |
30
- | `POST /api/logout` | destrói a sessão no servidor |
31
- | `GET /api/me` | protegida — devolve o usuário da sessão, ou 401 |
32
- | `POST /api/forgot-password` | token aleatório, guardado só como hash SHA-256, 15 min |
33
- | `POST /api/reset-password` | valida o token (uso único) e troca o hash da senha |
34
-
35
- ### Dados do usuário — todas exigem sessão e filtram por `owner`
36
- | Rota | O que faz |
37
  |---|---|
38
- | `GET/POST /api/habits`, `PUT/DELETE /api/habits/:id` | hábitos do usuário logado (emoji, cor, diário/semanal com meta) |
39
- | `GET /api/checkins`, `POST /api/checkins/toggle` | conclusões diárias (`{habitId, date}`), valida posse do hábito |
40
- | `GET/POST /api/tasks`, `PUT/DELETE /api/tasks/:id`, `POST /api/tasks/reorder` | tarefas com prioridade e prazo, reordenação por lista de ids |
41
- | `GET/POST /api/sessions` | sessões de foco (pomodoro) |
42
- | `GET /app` | página do planner — **redireciona para `/` sem sessão** |
43
-
44
- ## Detalhes de segurança
45
-
46
- - **bcrypt** com 10 rounds — senha nunca em texto puro.
47
- - **Sessão server-side**: cookie `planner.sid` é `httpOnly`, `sameSite=lax`, `Secure` automático atrás do HTTPS do Space; secret gerado com `crypto.randomBytes` e persistido.
48
- - **Regeneração de sessão no login** (anti fixação) e rate limit no login.
49
- - **`/app` fora do express.static**: o arquivo vive em `private/` e só é servido pela rota que exige sessão — não há como baixá-lo direto.
50
- - **Isolamento por usuário no servidor**: cada rota de dados filtra por `owner = sessão atual`; um usuário não pode ler nem alterar dados de outro, mesmo forjando ids.
51
- - **Token de reset** como hash SHA-256, uso único, expiração; resposta de "esqueci a senha" idêntica para e-mail existente ou inexistente.
52
-
53
- ## Limitações honestas
54
-
55
- - Armazenamento em `data/db.json` (troque por SQLite/Postgres em produção).
56
- - Sessões em memória (`MemoryStore`) — não sobrevivem a restart do Space; use Redis em produção.
57
- - Sem e-mail no Space: o token de reset volta na resposta da API (demo). Em produção iria por e-mail.
58
- - Sem CSRF token explícito (`sameSite=lax` cobre o caso básico); sem HTTPS próprio (proxy do Space cuida).
 
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).