Overview
The TechStore API provides a complete authentication system with email verification, JWT-based authentication, and password recovery functionality. All authentication endpoints are publicly accessible and do not require authentication.Register User
Endpoint
POST
/api/auth/registerRequest Body
User’s first name
User’s last name (max 100 characters)
User’s email address. Must be unique in the system
User’s password. Will be encrypted using BCrypt before storage
User’s phone number (max 20 characters)
User’s address (max 255 characters)
Response
Success message indicating the user should check their email for verification
Behavior
- The password is automatically encrypted using BCrypt
- A unique verification token (UUID) is generated and stored
- User account is created with
enabled: falsestatus - A verification email with HTML design is sent to the provided email address
- User cannot log in until email is verified
The email service runs asynchronously. If email sending fails, the user is still registered but won’t receive the verification email. Check server logs for email delivery issues.
Verify Account
Endpoint
GET
/api/auth/verificarQuery Parameters
The unique verification token sent to the user’s email during registration
Response
This endpoint returns HTML content, not JSON. It’s designed to be accessed directly from a browser via the email verification link.Behavior
- Validates the provided token against stored user tokens
- If valid, sets user’s
enabledfield totrue - Clears the verification token to prevent reuse
- Returns visual HTML feedback suitable for browser display
Login
Endpoint
POST
/api/auth/loginRequest Body
User’s registered email address
User’s password (sent in plain text, compared against BCrypt hash)
Response
User’s unique identifier
JWT access token for authenticated requests. Valid for 10 hours (36000 seconds)
User’s email address
User’s first name
User’s primary role (e.g., “ROLE_USER” or “ROLE_ADMIN”)
JWT Token Details
The access token is a signed JWT (JSON Web Token) with the following characteristics:RSA256 (2048-bit RSA key pair)
10 hours (36000 seconds) from issuance
Using the JWT Token
Include the token in subsequent API requests using theAuthorization header:
The user must have verified their email (enabled=true) before they can successfully log in. Registration alone is not sufficient.
Forgot Password
Endpoint
POST
/api/auth/forgot-passwordRequest Body
The email address of the account that needs password recovery
Response
Success message confirming recovery email was sent
Error message if the email was not found
Behavior
- Checks if a user exists with the provided email address
- Generates a new UUID token and stores it in the user’s
tokenVerificacionfield - Sends a recovery email with the token to the user’s email address
- Returns success message (even if email sending fails, to prevent email enumeration)
For security reasons, the API does not reveal whether an email exists in the system through different response times or messages. Always returns a success message if the request is properly formatted.
Reset Password
Endpoint
POST
/api/auth/reset-passwordRequest Body
The password reset token received via email from the forgot-password endpoint
The new password to set for the account. Will be encrypted using BCrypt before storage
Response
Success message confirming password update
Error message if token is invalid or expired
Behavior
- Validates the provided token against stored user tokens
- Encrypts the new password using BCrypt
- Updates the user’s password with the encrypted version
- Clears the reset token to prevent reuse
- Returns confirmation message
Security Notes
- The new password is automatically encrypted using BCrypt (same algorithm as registration)
- No password strength validation is performed server-side (implement client-side validation)
- Old sessions/tokens remain valid after password reset
- Users should log in again with their new password
Authentication Flow
User Registration
User submits registration form with email and password
- Password is encrypted with BCrypt
- Verification token is generated
- User record created with
enabled: false - Verification email sent
Email Verification
User clicks verification link in email
- Token is validated
- Account is enabled (
enabled: true) - User can now log in
Login
User submits email and password
- Credentials validated
- Account enabled status checked
- JWT token generated (10-hour expiry)
- Token and user details returned
Password Recovery Flow
Request Recovery
User submits forgot-password request with email
- New recovery token generated
- Recovery email sent with token
Reset Password
User clicks link and submits new password
- Token validated
- Password encrypted and updated
- Token invalidated
Security Configuration
CORS Settings
The API accepts requests from the following origins:http://localhost:63342http://127.0.0.1:5500http://127.0.0.1:63342http://localhost:8080
Session Management
- Session Policy: Stateless (no server-side sessions)
- CSRF Protection: Disabled (using JWT tokens)
- Authentication Type: JWT Bearer tokens
Public Endpoints
All/api/auth/** endpoints are publicly accessible and do not require authentication:
/api/auth/register/api/auth/verificar/api/auth/login/api/auth/forgot-password/api/auth/reset-password
Error Handling
All endpoints follow standard HTTP status codes:| Status Code | Meaning | Common Causes |
|---|---|---|
| 200 | Success | Request completed successfully |
| 400 | Bad Request | Missing required fields, invalid data format |
| 401 | Unauthorized | Invalid credentials, wrong password |
| 403 | Forbidden | Account not verified/enabled |
| 404 | Not Found | User/email not found in system |
| 500 | Internal Server Error | Database errors, unexpected exceptions |
Error messages are returned in Spanish to match the application’s target audience. Consider this when building client applications.