Relay Widget SDK Reference

This page documents the full client-side API for the Persona Relay SDK.

Installation

Available on npm: @persona/relay

$npm install @persona/relay

Constructors

new Relay(container, options)

1new Relay(container: string | HTMLElement, options: RelayOptions)

Arguments

ArgumentTypeRequiredDescription
containerstring | HTMLElementtrueA CSS selector string (e.g. '#relay-container') or a direct DOM element reference to mount the widget into
accessTokenstringtrueThe relay session access token returned by your server
onComplete() => voidfalseCalled when relay verification completes successfully
onError(error: RelayError) => voidfalseCalled when a configuration or network error occurs
onExpire() => voidfalseCalled when the relay session expires
theme'light' | 'dark' | 'auto'falseColor theme for the widget. Defaults to 'auto', which follows the user’s OS color scheme preference

RelayError

FieldTypeDescription
codestringMachine-readable error code
messagestringOptional human-readable error description

Methods

client.destroy()

Unmounts the widget, removes all iframes from the DOM, and cleans up all event listeners and observers. Call this when the widget is no longer needed.

1// React example
2useEffect(() => {
3 const client = new Relay('#relay-container', { ... });
4 return () => client.destroy();
5}, []);