Skip to main content

AuthConsoleChannel

WIP

Logs messages to stdout for development. Plus AuthTestChannel (captures into an outbox) and AuthNoopChannel (discards).

When to use

  • Development: see magic-link URLs and password-reset codes printed directly in your terminal, without setting up SMTP.
  • Tests: AuthTestChannel captures every send into an array for assertion.
  • Benchmarks: AuthNoopChannel discards sends, so you measure AuthEngine throughput without an outbound bottleneck.

AuthConsoleChannel is never appropriate for production.

AuthConsoleChannel

import { AuthConsoleChannel } from '@gentleduck/auth/channels/console'

const channel = new AuthConsoleChannel({
  kind: 'email',                       // | 'sms' | 'webpush'
  id: 'console',                       // shown in audit events
  sink: (line) => console.log(line),   // optional override
})

When the provider sends through channel.send({...}), the channel prints a JSON line:

{"templateId":"magic-link","identity":{"id":"identity-1"},"vars":{"email":"ada@example.com","url":"...","expiresAt":"..."}}

The sink override is useful in tests if you want to capture lines into a buffer instead of stdout.

AuthTestChannel

import { AuthTestChannel } from '@gentleduck/auth/channels/console'

const channel = new AuthTestChannel({ kind: 'email' })

// ... run the test, trigger a provider send ...

expect(channel.outbox).toHaveLength(1)
expect(channel.outbox[0]).toMatchObject({
  templateId: 'magic-link',
  vars: { email: 'ada@example.com' },
})

channel.outbox = []  // clear between assertions

The outbox is a public array; treat it as inspectable test state.

AuthNoopChannel

import { AuthNoopChannel } from '@gentleduck/auth/channels/console'

const channel = new AuthNoopChannel({ kind: 'email' })

Returns { ok: true, providerMessageId: 'noop:<incrementing>' } without doing anything. Use this when running benchmarks against AuthEngine itself and you don't want SMTP / API latency in the measurement.