Overview
The Directus SDK provides multiple authentication methods to suit different use cases. You can use full authentication with login/logout/refresh capabilities, or use a static token for server-side applications.Authentication Methods
Static Token
Use a static access token for server-side applications or when you already have a valid token.- TypeScript
- JavaScript
Full Authentication
Use theauthentication() composable for full login/logout capabilities with automatic token refresh.
Authentication Modes
cookie- Uses HTTP-only cookies (default, recommended for web apps)json- Returns tokens in JSON response body (for mobile/desktop apps)
Cookie Mode (Default)
- TypeScript
- JavaScript
JSON Mode
- TypeScript
- JavaScript
LDAP Authentication
For LDAP authentication, provide the provider option:- TypeScript
- JavaScript
Two-Factor Authentication (OTP)
If the user has 2FA enabled, provide the one-time password:- TypeScript
- JavaScript
Token Management
Get Current Token
Set Token Manually
Automatic Token Refresh
The SDK automatically refreshes tokens before they expire when usingauthentication() mode.
Configuration
Manual Refresh
Stop Auto-Refresh
Custom Storage
By default, authentication data is stored in memory. You can provide custom storage (e.g., localStorage, AsyncStorage):CORS Credentials
For cross-origin requests with cookies:Authentication Type Signatures
Next Steps
Items Operations
Perform CRUD operations on collection items
Users
Manage users and retrieve current user info
Files
Upload and manage files
Real-time
Subscribe to real-time updates