Overview
The registration endpoint allows new users to create an account in the Library Management system. The registration process creates both an authentication record (AuthUser) and a user profile record (User) in a single atomic transaction.
Registration Endpoint
Request Format
Endpoint Details
- URL:
/api/v1/auth/register - Method:
POST - Content-Type:
application/json - Authentication: Not required (public endpoint)
Request Body Schema
The request body must be a JSON object conforming to theAuthRegisterRequest DTO:
Field Requirements
| Field | Type | Required | Validation | Description |
|---|---|---|---|---|
name | String | Yes | Not blank | User’s full name |
birthDate | String (ISO 8601) | Yes | Must be past or present date | User’s date of birth in YYYY-MM-DD format |
username | String | Yes | Not blank, must be unique | Desired username for the account |
password | String | Yes | Not blank | Password for the account (will be encrypted) |
email | String | Yes | Valid email format, must be unique | User’s email address |
All fields are mandatory and will be validated according to the constraints defined in the
AuthRegisterRequest DTO.Validation Rules
Field-Level Validation
Birth Date Validation
- Must be a valid ISO 8601 date (YYYY-MM-DD)
- Must be in the past or present (not future)
- Will be parsed to
LocalDate
Password Validation
- Must not be blank
- No minimum length enforced at API level (consider implementing in production)
- Will be hashed using BCrypt before storage
Response Format
Success Response (201 Created)
Response Fields
| Field | Type | Description |
|---|---|---|
username | String | The username of the newly created account |
email | String | The email address associated with the account |
message | String | Confirmation message (“User successfully registered”) |
status | Boolean | Always true for successful registration |
Registration Process
The registration process follows these steps:Validate Request Data
The API validates all fields against their constraints (required, format, etc.)
The registration process is transactional (annotated with
@Transactional). If any step fails, all database changes are rolled back to maintain data integrity.Password Security
BCrypt Hashing
Passwords are never stored in plain text. The API uses BCrypt, a secure one-way hashing algorithm:BCrypt Features
- One-way hashing: Cannot reverse the hash to get the original password
- Salt integration: Each password has a unique salt automatically generated
- Adaptive: Computational cost can be adjusted as hardware improves
- Slow by design: Makes brute-force attacks computationally expensive
Error Responses
Username Already Exists (409 Conflict)
Email Already Exists (409 Conflict)
Validation Errors (400 Bad Request)
Complete Registration Example
Step-by-Step Registration
Best Practices
For API Consumers
- Validate Input Client-Side: Check format and required fields before sending the request
- Secure Password Handling: Never log or expose passwords in client code
- Handle Errors Gracefully: Provide clear feedback for username/email conflicts
- Redirect After Success: Guide users to the login page after successful registration
- Use HTTPS: Always communicate over secure connections
For API Developers
- Enforce Password Policies: Add minimum length and complexity requirements
- Rate Limiting: Implement rate limiting to prevent registration spam
- Email Verification: Consider adding email verification before activation
- Audit Logging: Log registration attempts for security monitoring
- Data Privacy: Ensure compliance with GDPR and other regulations
Database Records Created
AuthUser Table
Stores authentication credentials:| Column | Type | Value |
|---|---|---|
id | UUID | Generated UUID (shared with User table) |
name | String | User’s full name |
birth_date | LocalDate | User’s date of birth |
username | String | Unique username |
password | String | BCrypt hashed password |
email | String | Unique email address |
create_at | LocalDateTime | Auto-generated timestamp |
is_enable | Boolean | true |
account_no_expired | Boolean | true |
account_no_locked | Boolean | true |
credential_no_expired | Boolean | true |
User Table
Stores user profile information:| Column | Type | Value |
|---|---|---|
id | UUID | Same UUID as AuthUser |
user_name | String | Username |
name | String | Full name |
birth_date | LocalDate | Date of birth |
books | List | Empty list (initialized) |
The same UUID is used for both tables, establishing a one-to-one relationship between authentication credentials and user profile.
Testing Registration
Valid Registration Test
Expected Response
Next Steps
After successfully registering, users can:Login
Authenticate with your new credentials to receive a JWT token
JWT Tokens
Learn how to use JWT tokens for API requests
User Management
Explore user profile management endpoints
Books API
Start managing your book collection