Overview
Tambo360 uses JSON Web Tokens (JWT) for authentication. Tokens are stored in secure HTTP-only cookies and automatically included in requests by the browser.Authentication Flow
- User registers or logs in with credentials
- Server validates credentials and generates a JWT token
- Token is stored in an HTTP-only cookie with a 24-hour expiration
- Cookie is automatically sent with subsequent requests
- Server validates the token on protected routes
HTTP-only cookies prevent XSS attacks by making tokens inaccessible to JavaScript. The browser automatically handles token storage and transmission.
Security Scheme
The API uses cookie-based authentication:Token Structure
The JWT payload contains:Token Payload
Registration
Create a new user account.Endpoint
Request Body
Full name of the user (5-50 characters)
Valid email address (5-50 characters)
Password meeting security requirements:
- Minimum 8 characters, maximum 50
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character (@$!%*?&)
Example Request
Response
HTTP status code:
201 for successSuccess message
201 Success Response
400 Validation Error
Login
Authenticate a user and receive a JWT token.Endpoint
Request Body
User’s email address
User’s password
Example Request
Response
HTTP status code:
200 for successSuccess message
200 Success Response
The token is automatically stored in an HTTP-only cookie named
token with:httpOnly: true- Prevents JavaScript accesssecure: true- HTTPS only (production)sameSite: 'none'- Cross-site requests (production) or'lax'(development)maxAge: 86400000- 24 hour expiration
Get Current User
Retrieve the authenticated user’s information.Endpoint
Authentication
Must include the
token cookie from loginExample Request
Response
200 Success Response
401 Unauthorized
Logout
End the user’s session by clearing the authentication cookie.Endpoint
Authentication
Must include the
token cookieExample Request
Response
200 Success Response
Email Verification
Verify a user’s email address using a verification token.Endpoint
Request Body
Email verification token sent to the user’s email
Example Request
Response
200 Success Response
400 Invalid Token
Resend Verification Email
Resend the email verification link to a user.Endpoint
Request Body
User’s email address
Example Request
Response
200 Success Response
Password Reset Flow
The password reset process involves three steps:Step 1: Request Password Reset
Request a password reset token to be sent via email.Endpoint
Request Body
User’s email address
Example Request
Response
200 Success Response
Step 2: Verify Reset Token
Verify that the password reset token is valid.Endpoint
Request Body
Password reset token from email
Example Request
Response
200 Success Response
Step 3: Reset Password
Reset the password using the verified token.Endpoint
Request Body
Password reset token from email
New password meeting security requirements (same as registration)
Example Request
Response
200 Success Response
Authentication Errors
Common authentication errors and their meanings:401 Unauthorized
Occurs when:- No authentication token is provided
- Token is invalid or malformed
- Token has expired (after 24 hours)
Error Response
Token Error Response
400 Bad Request
Occurs when:- Missing required fields (email, password, etc.)
- Invalid email format
- Password doesn’t meet security requirements
- Account already exists
Validation Error
Protected Routes
Routes that require authentication will return401 Unauthorized if the token is missing or invalid. Always check the response status and handle authentication errors appropriately.
Example: Handling Authentication
javascript
Token Refresh
Security Best Practices
1. Never Store Tokens in LocalStorage
HTTP-only cookies are automatically used and provide better security than localStorage:Good Practice
2. Use HTTPS in Production
Always use HTTPS in production to prevent token interception:- The
secureflag is automatically set on cookies in production - Ensures encrypted communication
3. Handle Token Expiration
Implement proper error handling for expired tokens:javascript
4. Validate Input Client-Side
Reduce attack surface by validating before sending:javascript
Next Steps
API Overview
Learn about API structure and best practices
Establishments
Manage farm establishments (requires authentication)
Dashboard
Access analytics and metrics
Error Handling
Handle API errors effectively
