Skip to main content

Local Development

TruSec provides a seamless local development experience with our development mode and testing utilities.

Development Mode

Enable development mode to bypass certain security restrictions during local development:
import { TruSec } from '@trusec/sdk';

const trusec = new TruSec({
  apiKey: process.env.TRUSEC_SECRET_KEY,
  development: true, // Enable development mode
});
Never enable development mode in production. It disables certain security checks that are essential for protecting your users.

Test API Keys

Use test API keys for development and testing. Test keys have the prefix trusec_test_:
TRUSEC_SECRET_KEY=trusec_test_sk_1234567890abcdef
Test keys work exactly like production keys but operate in an isolated sandbox environment.

Testing

Mock Client

For unit testing, use our mock client to simulate TruSec responses:
import { MockTruSec } from '@trusec/sdk/testing';

const mockTrusec = new MockTruSec();

// Configure mock responses
mockTrusec.sessions.verify.mockResolvedValue({
  valid: true,
  user: { id: 'user_123', email: '[email protected]' },
});

// Use in your tests
const session = await mockTrusec.sessions.verify({ token: 'test-token' });
expect(session.valid).toBe(true);

Integration Testing

For integration tests, we recommend using test API keys with our sandbox environment:
describe('TruSec Integration', () => {
  const trusec = new TruSec({
    apiKey: process.env.TRUSEC_TEST_KEY,
    baseUrl: 'https://sandbox.trusec.io',
  });

  it('should authenticate a valid user', async () => {
    const session = await trusec.sessions.create({
      email: '[email protected]',
      password: 'test-password-123',
    });

    expect(session.token).toBeDefined();
  });
});

Debugging

Enable Verbose Logging

Enable verbose logging to see detailed request/response information:
const trusec = new TruSec({
  apiKey: process.env.TRUSEC_SECRET_KEY,
  debug: true,
  logLevel: 'verbose',
});

Request Tracing

Every request includes a trace ID for debugging. Access it from the response:
const response = await trusec.users.get({ id: 'user_123' });
console.log('Trace ID:', response._traceId);
Include the trace ID when contacting support for faster issue resolution.