Skip to main content

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.

Full Authentication

Use the authentication() 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)

JSON Mode

LDAP Authentication

For LDAP authentication, provide the provider option:

Two-Factor Authentication (OTP)

If the user has 2FA enabled, provide the one-time password:

Token Management

Get Current Token

Set Token Manually

Automatic Token Refresh

The SDK automatically refreshes tokens before they expire when using authentication() 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