Authentication
Forgot Password
Request a password reset email. Anti-enumeration — always returns success regardless of account existence.
POST /api/v1/auth/forgot-password — 🌐 Public · Rate limit: 5 req / hour
Initiates the password reset flow. If the email is registered + active, a reset email is queued (worker-service). Returns success even if the account is unknown — anti-enumeration.
Privacy by default: response is 200 OK regardless of whether the email is registered. Client should display a generic "If the address is registered, a reset email has been sent." Do not infer account existence from this response.
Request
Body — ForgotPasswordDto
| Field | Type | Required | Validation | Notes |
|---|---|---|---|---|
email | string (RFC 5322) | ✓ | Trimmed + lowercased | Lookup against User.email |
Response
200 OK — ApiResponseOf<MessageResponseDto>
{ "success": true, "data": { "message": "Password reset email sent if account exists" } }Errors
| HTTP | code / i18nKey | Reason |
|---|---|---|
429 | (throttle) | Rate limit exceeded (5 req/hour — strict to deter enumeration + spam) |
Side effects
- Lookup
Userby email; always returns success (anti-enumeration). - If user exists + active + email-verified: invalidate prior
PasswordResetrecords, create new token, queue reset email (worker-service). - Audit log:
auth.forgot_password.requested(always logged regardless of account existence).
Code samples
curl -X POST https://api.bio.re/api/v1/auth/forgot-password \
-H 'Content-Type: application/json' \
-d '{"email": "[email protected]"}'async function forgotPassword(email: string): Promise<{ message: string }> {
const res = await fetch('https://api.bio.re/api/v1/auth/forgot-password', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email }),
});
const json = await res.json();
if (!res.ok || !json.success) {
throw Object.assign(new Error(json?.error?.message ?? 'Request failed'), {
code: json?.error?.code,
});
}
return json.data;
}import { useMutation } from '@tanstack/react-query';
export function useForgotPassword() {
return useMutation({
mutationFn: async (email: string) => {
const res = await fetch('/api/v1/auth/forgot-password', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email }),
});
const json = await res.json();
if (!res.ok || !json.success) {
throw Object.assign(new Error(json?.error?.message ?? 'Request failed'), {
code: json?.error?.code,
});
}
return json.data;
},
});
}Try it
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
curl -X POST "https://loading/api/v1/auth/forgot-password" \ -H "Content-Type: application/json" \ -d '{ "email": "[email protected]" }'{
"success": true,
"data": {
"message": "Operation completed successfully"
}
}{
"success": false,
"error": {
"code": "AUTH_UNAUTHORIZED",
"message": "Invalid credentials",
"i18nKey": "auth.login.invalid_credentials",
"i18nVars": {
"field": "email"
},
"details": [
{
"message": "email must be an email"
}
],
"correlationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
}Source
| Source | Path | Lines |
|---|---|---|
| Controller | apps/api-core/src/modules/auth/auth.controller.ts | 204–212 |
| DTO (request) | apps/api-core/src/modules/auth/dto/index.ts | 108–113 (ForgotPasswordDto) |
| Service | apps/api-core/src/modules/auth/auth.service.ts | forgotPassword() |
| Prisma models | packages/prisma/prisma/schema.prisma | User, PasswordReset |