User Registration & Email Verification
RESTHeartRegistration flow
POST /auth/register is the public signup endpoint. It creates a new user and a new tenant in a single atomic operation.
Request
POST /auth/register
Content-Type: application/json
{
"firstName": "Alice",
"lastName": "Rossi",
"teamName": "Acme",
"email": "alice@acme.com",
"password": "correct-horse-battery"
}
Server-side steps
-
Validate all required fields.
-
Enforce password strength via zxcvbn (score ≥
minimumPasswordStrength, default 3). -
Check email uniqueness —
409 Conflictif already registered. -
Generate a cryptographically random
verificationToken(256-bit) andverificationCreatedAttimestamp. -
Create the tenant document (
status: active). -
Create the user document (
status: pending_verification) with the verification token. -
Create a
membershipdocument linking the user to the tenant asowner. -
Send a verification email containing a one-time link:
{baseAppUrl}/auth/verify?email=alice@acme.com&token=<verificationToken> -
Return
201 Created.
Response
{ "message": "Registration successful. Check your email to verify your address." }
Error responses
| Status | Reason |
|---|---|
|
Missing or invalid fields; password too weak |
|
Email already registered |
Email verification
GET /auth/verify?email=…&token=… is sent as a link in the registration email.
Server-side steps
-
Extract
emailandtokenfrom the query string. -
Find the user by email.
-
Compare
tokenagainstverificationTokenusing constant-time comparison (timing-attack mitigation). -
Check that
verificationCreatedAtis within the TTL (verificationTokenTtlDays, default 7 days). -
Set
status: activeand$unset verificationToken verificationCreatedAt. -
Issue a JWT access token + refresh cookie.
-
Redirect to
{baseAppUrl}/app.
Expired token
If the token has expired, the endpoint returns 400 with a message inviting the user to request a new verification email from the login page.
|
Note
|
Re-sending a verification email is triggered by POST /auth/resend-verify (not yet implemented in v1 — users can contact support or attempt login which will prompt re-verification).
|