Authentication
Cocobase provides a robust authentication system supporting both administrative API keys and per-user JWT tokens.Authentication Methods
API Key Authentication
API keys are used for server-side operations and administrative tasks.- Header:
X-API-Key: your_api_keyorAuthorization: Bearer your_api_key - Use Case: Cloud functions, backend integrations, administrative scripts.
JWT Token Authentication
User tokens are obtained after login and are used for client-side user operations.- Header:
Authorization: Bearer <jwt_token> - Use Case: Frontend applications, mobile apps, user-specific data access.
Sign Up
Create a new user account.Endpoint
POST /auth-collections/signup
Request Body
Response
Login
Authenticate an existing user.Endpoint
POST /auth-collections/login
Request Body
Response
Get Current User
Retrieve the profile of the currently authenticated user.Endpoint
GET /auth-collections/user
Headers
Authorization: Bearer <jwt_token>
Update User
Update the current user’s data. Supports atomic array operations.Endpoint
PATCH /auth-collections/user
Atomic Array Operations
Use$append and $remove to modify array fields (like followers/following) without fetching-and-saving.
Follow a User ($append)
Unfollow a User ($remove)
Update with File Upload
To update a user with files (e.g., avatar), usemultipart/form-data.
Change Password
Update the user’s password.Endpoint
POST /auth-collections/change-password
Request Body
List Users
List all users in the project. Requires API Key.Endpoint
GET /auth-collections/users
Query Parameters
limit: Number of users to returnoffset: Skip results for paginationrole: Filter by roleemail_contains: Search by email content
Get User by ID
Retrieve a specific user’s public profile.Endpoint
GET /auth-collections/users/{id}
OAuth Authentication
Cocobase supports Google and Apple OAuth.1. Get OAuth Google URL
GET /auth-collections/oauth/google?redirect_uri=https://yourapp.com/callback
2. Verify Google Login
POST /auth-collections/verify-google-login
User Relationships
Users can have relationships likefollowers and following. These are typically stored as arrays of IDs in the user data object.
| Relationship | ID Pattern |
|---|---|
| Following | following_ids |
| Followers | followers_ids |
| Meta | referral_code |
Examples
- JavaScript
- Python
Best Practices
- Security: Never expose Live API keys (
sk_live_...) in client-side code. - Tokens: Refresh JWT tokens before they expire to maintain session persistence.
- Atomic Operations: Always use
$appendand$removefor array updates to avoid race conditions. - Validation: Validate email formats and password strength on the frontend before submitting to the API.
Rate Limits
| Tier | Limit |
|---|---|
| Free | 60 requests / minute |
| Pro | 1000 requests / minute |
| Enterprise | Custom |
