Documentation Index
Fetch the complete documentation index at: https://usegately.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Initialization Options
import { GatelyClient } from '@gately/sdk'
const gately = new GatelyClient({
// Required: Your API key
apiKey: 'gately_pk_live_xxxxxxxx',
// Optional configuration
apiUrl: 'https://api.usegately.com',
autoRefresh: true,
suppressConsoleErrors: false
})
Options Reference
apiKey (Required)
Your Gately API key. Use public keys (gately_pk_) for browser apps and secret keys (gately_sk_) for server-side only.
const gately = new GatelyClient({
apiKey: 'gately_pk_live_xxxxxxxx'
})
Never expose secret API keys (gately_sk_) in client-side code. Use public keys for browser applications.
apiUrl
The base URL for API requests. Only change this for self-hosted deployments.
const gately = new GatelyClient({
apiKey: 'gately_pk_live_xxxxxxxx',
apiUrl: 'https://your-custom-domain.com'
})
| Type | Default |
|---|
string | https://api.usegately.com |
autoRefresh
Automatically refresh the session before it expires.
const gately = new GatelyClient({
apiKey: 'gately_pk_live_xxxxxxxx',
autoRefresh: true // Enabled by default
})
When enabled, the SDK will:
- Monitor session expiry time
- Refresh the token 5 minutes before expiry
- Update stored session automatically
suppressConsoleErrors
Suppress error messages in the browser console.
const gately = new GatelyClient({
apiKey: 'gately_pk_live_xxxxxxxx',
suppressConsoleErrors: true // Useful in production
})
React Provider Configuration
import { GatelyProvider } from '@gately/sdk'
function App() {
return (
<GatelyProvider
apiKey={process.env.NEXT_PUBLIC_GATELY_API_KEY}
options={{
autoRefresh: true,
suppressConsoleErrors: process.env.NODE_ENV === 'production'
}}
>
<YourApp />
</GatelyProvider>
)
}
CDN Configuration
Configure via data attributes:
<script
src="https://cdn.usegately.com/gately.min.js"
data-api-key="YOUR_API_KEY"
data-api-url="https://api.usegately.com"
data-auto-refresh="true"
data-auto-protect="true"
defer
></script>
| Attribute | Description |
|---|
data-api-key | Your API key (required) |
data-api-url | Custom API URL |
data-auto-refresh | Enable auto session refresh |
data-auto-protect | Enable automatic page protection |
Environment-Based Configuration
const config = {
development: {
apiKey: process.env.GATELY_API_KEY_DEV,
apiUrl: 'http://localhost:8787',
suppressConsoleErrors: false
},
production: {
apiKey: process.env.GATELY_API_KEY,
apiUrl: 'https://api.usegately.com',
suppressConsoleErrors: true
}
}
const env = process.env.NODE_ENV || 'development'
const gately = new GatelyClient(config[env])
Server-Side Configuration (Node.js)
For server-side applications, use your secret API key:
import { GatelyNodeClient } from '@gately/sdk/node'
const gately = new GatelyNodeClient({
apiKey: process.env.GATELY_SECRET_KEY // gately_sk_live_xxxxxxxx
})
Always use environment variables for secret keys. Never commit them to version control.
Session Storage
By default, sessions are stored in localStorage. The SDK also sets cookies for cross-origin compatibility:
| Cookie | Purpose |
|---|
gately_auth_token | JWT access token |
gately_session | Session data |
Debugging
Enable verbose logging for debugging:
// In browser console
localStorage.setItem('gately_debug', 'true')
// Then reload the page
location.reload()
This will log:
- API requests and responses
- Session management events
- Page protection checks
- OAuth flow details
To disable:
localStorage.removeItem('gately_debug')
location.reload()