Set Up Authentication
Configure API keys and secure access to your DeltaBase instance
Get your API key
Section titled “Get your API key”First, you need an API key. During early access, we’ll send you one manually.
Join the Discord and ask for access: https://discord.gg/nibbio
Once you have your key, store it securely.
Configure the client
Section titled “Configure the client”Environment variables
Section titled “Environment variables”Never hardcode API keys. Use environment variables:
DELTABASE_API_KEY=dbk_your_actual_key_hereDELTABASE_URL=https://api.delta-base.com
Initialize the client
Section titled “Initialize the client”import { DeltaBase } from '@delta-base/server';
const deltabase = new DeltaBase({ apiKey: process.env.DELTABASE_API_KEY!, baseUrl: process.env.DELTABASE_URL || 'https://api.delta-base.com'});
Multi-tenant setup
Section titled “Multi-tenant setup”If you’re building a SaaS app, you’ll want tenant isolation:
// Each tenant gets their own event storeconst getTenantEventStore = (tenantId: string) => { return deltabase.getEventStore(`tenant-${tenantId}`);};
// Usage in your APIapp.use('/api', async (req, res, next) => { const tenantId = req.headers['x-tenant-id']; if (!tenantId) { return res.status(400).json({ error: 'Tenant ID required' }); }
req.eventStore = getTenantEventStore(tenantId); next();});
Error handling
Section titled “Error handling”Handle auth errors gracefully:
try { await eventStore.appendToStream('stream-1', [event]);} catch (error) { if (error.status === 401) { console.error('Invalid API key'); // Refresh key or redirect to login } else if (error.status === 403) { console.error('Insufficient permissions'); // Show error to user } else { console.error('Unexpected error:', error); }}
Key rotation
Section titled “Key rotation”When you need to rotate keys:
- Get new key from DeltaBase team
- Update environment variable
- Restart your application
- Old key is automatically revoked
That’s it. No complex OAuth flows. No token management. Just works.