Overview
The authentication system provides:- User registration with email verification
- Secure login with JWT token management
- Password recovery and reset functionality
- HTTP-only cookie-based session management
- Production-ready security configurations
User Registration
Create Account
Users register with their name, email, and password. The system validates all inputs against security requirements.
Email Verification
After registration, a verification email is sent to the user. The account remains unverified until the email link is clicked.Users can request a new verification email if needed:
Login Process
Standard Login
Users authenticate with email and password:JWT Token Structure
The JWT token contains:Tokens expire after 24 hours (1d). Users must re-authenticate after expiration.
Cookie Management
Tokens are stored in HTTP-only cookies for enhanced security:- Development
- Production
secure: false (allows HTTP)sameSite: lax
Password Recovery
Request Reset
Users can request a password reset by providing their email:An email with a reset link and token is sent to the user.
Session Management
Get Current User
Retrieve authenticated user information:Logout
Securely terminate user session:Frontend Integration
The frontend implements the authentication flow in the Login component:Login Component Flow
Login Component Flow
Registration Flow
Registration Flow
Security Best Practices
Password Security
- Passwords hashed with bcrypt
- Complex password requirements enforced
- Maximum length limits prevent DoS attacks
Token Security
- JWT signed with secret key
- HTTP-only cookies prevent XSS
- 24-hour expiration limits exposure
API Security
- All endpoints validate input
- Error messages don’t leak sensitive info
- Rate limiting recommended for production
HTTPS Enforcement
- Secure cookies in production
- Environment-based configuration
- SameSite policies for CSRF protection
Common Issues
Email not verified
Email not verified
If users try to log in without verifying their email, they can still authenticate, but the
verificado flag will be false. Implement UI checks to prompt verification.Token expired
Token expired
After 24 hours, the JWT expires. Users must log in again. Implement token refresh logic or session extension if needed.
Forgot password not working
Forgot password not working
Ensure email service is configured correctly. Check email provider settings and verify the reset token hasn’t expired.
API Reference
| Endpoint | Method | Purpose |
|---|---|---|
/api/auth/register | POST | Create new user account |
/api/auth/login | POST | Authenticate user and issue token |
/api/auth/verify-email | POST | Verify email with token |
/api/auth/resend-verification | POST | Resend verification email |
/api/auth/forgot-password | POST | Request password reset |
/api/auth/verify-reset-token | POST | Validate reset token |
/api/auth/reset-password | POST | Set new password |
/api/auth/me | GET | Get current user info |
/api/auth/logout | POST | End user session |
