Skip to main content
The SnackBase JavaScript SDK provides many configuration options to customize its behavior for your application’s needs.

Configuration Options

Required Options

baseUrl

The base URL of your SnackBase instance.

Authentication Options

apiKey

Optional API key for server-to-server authentication.
API keys should only be used on the server side. Never expose API keys in client-side code.

defaultAccount

Default account slug for single-tenant applications.
When set, users don’t need to specify the account when logging in.

Request Options

timeout

Request timeout in milliseconds. Default: 30000 (30 seconds).

maxRetries

Maximum number of retry attempts for failed requests. Default: 3.

retryDelay

Delay between retry attempts in milliseconds. Default: 1000.

Storage Options

storageBackend

Storage backend for authentication tokens. Default: auto-detected based on platform.
Available options:

Token Refresh Options

enableAutoRefresh

Enable automatic token refresh before expiry. Default: true.

refreshBeforeExpiry

Seconds before token expiry to refresh. Default: 300 (5 minutes).

Real-Time Options

maxRealTimeRetries

Maximum reconnection attempts for real-time connections. Default: 10.

realTimeReconnectionDelay

Initial delay for real-time reconnection in milliseconds. Default: 1000.

Logging Options

enableLogging

Enable request/response logging. Default: false in production.

logLevel

Logging level. Default: 'error'.

Error Callbacks

onAuthError

Callback for 401 authentication errors.

onNetworkError

Callback for network failures.

onRateLimitError

Callback for 429 rate limit errors.

Complete Configuration Example

Accessing Configuration

You can access the current configuration at runtime:

Environment-Specific Configuration

Development

Production

With React

Default Configuration

These are the default values used by the SDK: