TryMellon
Navigation

Installation

Install and configure the TryMellon JavaScript SDK.

Installation

Install from npm

npm install @trymellon/js

Entry points

ImportExportsUse case
@trymellon/jsTryMellon, types, utilitiesCore SDK — Vanilla JS, Svelte, Node
@trymellon/js/reactTryMellonProvider, useAuthenticate, useRegister, useEnrollReact 18+ hooks & provider
@trymellon/js/vueprovideTryMellon, useAuthenticate, useRegister, useEnrollVue 3 Composition API composables
@trymellon/js/angularTryMellonService, provideTryMellonAngular standalone service & DI
@trymellon/js/ui<trymellon-auth>, <trymellon-auth-modal>Web Components (zero-framework drop-in)
@trymellon/js/umdwindow.TryMellonUMD bundle — via <script> tag

Initialize the client

import { TryMellon } from '@trymellon/js'

const clientResult = TryMellon.create({
  appId: 'YOUR_APP_ID',             // Required: Application ID from dashboard
  publishableKey: 'cli_xxxx',       // Required: Client ID (safe for browser)
  apiBaseUrl: 'https://api.trymellonauth.com', // Optional, default
  timeoutMs: 30000,                 // Optional, default 30000
  maxRetries: 3,                    // Optional, default 3
  retryDelayMs: 1000,               // Optional, default 1000
})

if (!clientResult.ok) {
  console.error(clientResult.error.message);
  throw clientResult.error;
}
const client = clientResult.value;

Where to get your credentials

  1. Sign up at the TryMellon dashboard.
  2. Create an Application — you’ll receive an App ID (UUID) and a Client ID (starts with cli_).
  3. Add your domain to Allowed Origins so the API accepts requests from your frontend.

Configuration options

OptionRequiredDefaultDescription
appIdYesApplication ID. Sent as X-App-Id header.
publishableKeyYesClient ID for client-side auth (safe for the browser).
apiBaseUrlNo'https://api.trymellonauth.com'API base URL. Override for self-hosted or staging environments.
timeoutMsNo30000HTTP request timeout (ms). Range: 1000–300000.
maxRetriesNo3Retries for transient network errors. Range: 0–10.
retryDelayMsNo1000Delay between retries (ms). Range: 100–10000.
loggerNoconsoleCustom logger implementing the Logger interface.
sandboxNofalseSkip API & WebAuthn calls; return a fixed token instantly. See Sandbox mode.
sandboxTokenNoSANDBOX_SESSION_TOKENCustom token returned in sandbox mode.
enableTelemetryNofalseOpt-in anonymous event + latency tracking.
originNowindow.location.originOverride the Origin header sent with API requests. Required in Node.js / SSR where window is not available.
contextHashStorageNosessionStorageCustom storage for the context hash used by enrollment flows. Must implement getItem / setItem. Useful for SSR or test environments.

Runtime compatibility

EnvironmentSupported
Modern browsers (Chrome, Safari, Firefox, Edge)Yes
Node.js 18+ (SSR/server validation)Yes
Edge runtimes (Cloudflare Workers, Vercel Edge)Yes
React NativeNo (WebAuthn requires a browser)

The SDK uses only globalThis.crypto and standard fetch — no Node-specific APIs.

For register and authenticate options you can use externalUserId (camelCase).