TryMellon

API Reference

API Reference

Condensed reference for the TreyMellon JavaScript SDK public API.

TryMellon

Main entry point. Create a client with your app configuration.

import { TryMellon } from '@trymellon/js';
const client = TryMellon.create({ appId: 'your-app-id' });

TryMellonConfig

  • appId (string, required): Your application ID from the dashboard.
  • apiUrl? (string): Override the API base URL (default: production TryMellon API).

register(options?)

Registers a new passkey for the user. Returns a Result with session_token on success.

const result = await client.register();
// or with options
const result = await client.register({ ... });

RegisterOptions

Optional overrides (e.g. rpId, userHandle) as per the WebAuthn flow. See the SDK types for full shape.

authenticate()

Authenticates the user with an existing passkey. Returns a Result with session_token on success.

const result = await client.authenticate();

validateSession()

Client-side check: validates the current session (e.g. via cookie). Returns a result indicating whether the session is valid. See Session validation (client-side).

getStatus()

Returns an object with at least webauthnAvailable (boolean). Use to decide whether to offer passkey or email fallback. See Session validation (client-side).

on(event, callback)

Subscribe to SDK events (e.g. for loading spinners or analytics).

client.on('start', () => { ... });
client.on('complete', () => { ... });
client.on('error', (err) => { ... });

Common events: start, complete, error. See Events & Error handling.

fallback.email

Email OTP fallback when WebAuthn is not available.

  • fallback.email.sendOtp({ email }): Sends OTP to the given email.
  • fallback.email.verifyOtp({ email, code }): Verifies the code and returns a session token (same shape as register/authenticate).

See Fallback by email.

Result type

All async methods that can fail return a Result<T, E>:

  • result.isOk(): true if success.
  • result.isErr(): true if error.
  • result.value: The success value (e.g. { session_token }).
  • result.error: The error (e.g. TryMellonError).

TryMellonError

Error type with at least a code and message. Use code for programmatic handling (e.g. user_cancelled, not_supported).