Advanced Developer Guides
Expand your ForgeKit application architecture by implementing enterprise scalability practices.
Multi-Tenant Database Connection Routing
In large SaaS systems, requests must connect dynamically to different database schemas depending on the workspace ID context.
To support dynamic database routing:
import app from '$lib/forgekit';
export const handle = async ({ event, resolve }) => {
const tenantId = event.request.headers.get('x-tenant-id') || 'public';
// Dynamically resolve connection pools depending on header parameters
event.locals.db = app.db.getTenantPool(tenantId);
return resolve(event);
}; Cryptographic Session Utilities
Secure password handling and cryptographic hashes inside user authentication controllers:
import { hashPassword, verifyPassword } from '@forgekit/auth/crypto';
// 1. Hash incoming credentials
const hash = await hashPassword('my-user-password');
// 2. Verify login attempts
const valid = await verifyPassword('my-user-password', hash);