Endpoint
Request
User’s email address. Must be unique.
User’s password. Will be hashed with bcrypt before storage.
Request Format
The endpoint expects form data (application/x-www-form-urlencoded or multipart/form-data).
Response
HTTP status code:
201 for success, 401 for errorsReturns
"Success" on successful registrationExample Request
Example Responses
Successful Registration (201)
Successful Registration (201)
Registration Error (401)
Registration Error (401)
- Email already registered
- Database connection issues
- Invalid email format
Implementation Details
User Creation Process
- UUID Generation: A unique UUID v4 is generated as the user ID
- Password Hashing: Password is hashed using bcrypt with cost factor 14
- Default Status: New users are created with
status: "pending" - Timestamp:
created_atis set to the current time - Database Storage: User document is inserted into MongoDB
userscollection
User Object Structure
The created user has the following initial structure:Source Code References
- Handler:
backend/auth/routes.go:29-HandleUserRegistration - Logic:
backend/auth/controller.go:30-createNewUser - Model:
backend/users/model.go:24-CreateNewUser
Error Handling
Errors are returned as JSON with HTTP status 401:- Duplicate Email: MongoDB unique constraint violation
- Hashing Failure: bcrypt.GenerateFromPassword error
- Database Error: MongoDB insertion failures
Security Considerations
- Passwords are never stored in plain text
- bcrypt cost factor of 14 provides strong security
- Email uniqueness is enforced at the database level
- New accounts start in “pending” status for verification workflows