Skip to content

Commit e9b827f

Browse files
committed
feat: implement #724, #740, #741, #742 - DEBUG_PII, docs, preflightChecks
1 parent 3f3f08a commit e9b827f

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

‎docs/Auth_and_User_APIs.md‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,50 @@ Success response (201 Created):
4040
Errors:
4141
- 400 Bad Request — validation failure (missing/weak password, invalid email)
4242
- 400 Bad Request — email already exists
43+
- 400 Bad Request — registration already pending from this IP
44+
45+
---
46+
47+
## Email verification flow
48+
49+
Purpose: verify the email address used during registration.
50+
51+
After a successful `POST /auth/register`, the newly created user has `isVerified: false` and
52+
cannot log in — login will return `401 Unauthorized` with the message
53+
`"Please verify your email before logging in."`.
54+
55+
The user receives an email containing a verification link that points to the
56+
`POST /auth/verify-email` endpoint:
57+
58+
**Request:**
59+
```json
60+
{ "token": "62-char-random-token" }
61+
```
62+
63+
**Success response (200 OK):**
64+
```json
65+
{
66+
"message": "Email verified successfully",
67+
"user": { "id": "user_abc123", "email": "user@example.com", "firstName": "Jane" },
68+
"accessToken": "ey...",
69+
"refreshToken": "ey..."
70+
}
71+
```
72+
73+
Errors:
74+
- 400 Bad Request — invalid or expired verification token
75+
- 400 Bad Request — email already verified
76+
77+
### Token expiry
78+
79+
The verification token expires after the duration configured in
80+
`EMAIL_VERIFICATION_EXPIRES_IN` (default: `24h`). When the token expires, the user must request
81+
a new verification email via `POST /api/users/email/resend` (or re-register).
82+
83+
### Registration from the same IP
84+
85+
To prevent abuse, a second registration from the same IP is blocked until the pending email
86+
verification is either completed or the token expires. This is a soft, in-memory guard.
4387

4488
---
4589

‎docs/CHANGELOG_GUIDE.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,45 @@ This guide explains how to maintain the project changelog for PropChain-BackEnd.
66

77
---
88

9+
## Log Redaction Policy
10+
11+
### What is redacted
12+
13+
The following PII (Personally Identifiable Information) is redacted in log output:
14+
15+
- **Email addresses**: replaced with a SHA-256 hash truncated to the first 12 characters
16+
(e.g. `user@example.com` → `a1b2c3d4e5f6`)
17+
18+
### How it works
19+
20+
The private `hashEmail(email)` helper in `AuthService` performs the redaction:
21+
22+
```typescript
23+
private hashEmail(email: string): string {
24+
return createSha256(email).slice(0, 12);
25+
}
26+
```
27+
28+
All log lines that reference a user's email address route through `hashEmail()` so that
29+
plaintext emails are never written to the logs.
30+
31+
### DEBUG_PII environment variable
32+
33+
| Variable | Default | Description |
34+
|--------------|---------|-----------------------------------------------------------------|
35+
| `DEBUG_PII` | `false` | When `true`, plaintext PII is logged instead of redacted values |
36+
37+
- **Local development**: set `DEBUG_PII=true` in `.env` to see real email addresses in logs.
38+
- **All other environments**: `DEBUG_PII` must remain `false` or unset.
39+
40+
### Security
41+
42+
Enabling `DEBUG_PII` in production would write sensitive user data to log files, creating
43+
a data-breach risk. CI/CD pipelines should verify that `DEBUG_PII` is not set to `true`
44+
in deployed environments.
45+
46+
---
47+
948
## 📍 Changelog Location
1049

1150
- **File**: `CHANGELOG.md` (root directory)

0 commit comments

Comments
 (0)