Truework.js is a JavaScript library that allows you to easily integrate Truework Direct into your online application or web portal, simplifying the process to verify consumer’s income and employment data securely and efficiently.
Use Truework.direct to initialize the widget. Truework.credentials is also supported for backward compatibility, but Truework.direct is the preferred API.
Load the script, create a session token on your backend (see Create a Truework Direct order; that guide focuses on the backend order/token flow and currently shows the legacy Truework.credentials initializer), then initialize and open the widget on the frontend using Truework.direct as shown below:
Include the Truework.js script once on the page where the widget will be used:
After the script loads, Truework is available on the global object.
/orders/truework-direct) and obtain a session token. See Make your first Truework Direct order for how to create an order and get the token; that guide currently uses the legacy Truework.credentials widget initializer, but the order/token creation steps are the same when using Truework.direct.Truework.direct.init({ publishableKey, sessionToken, env }), then call direct.open().onComplete when the user finishes the flow, onClose when the widget closes, and onError to handle errors.Best practices: Use one session token per widget open; do not reuse the same token for multiple opens. Use Truework.direct.Env.Sandbox and sandbox publishable keys for testing.
Truework.direct.init(config)Initializes the Truework Direct widget. Accepts one required argument, a config object. Returns a widget instance with methods to open/close the widget and subscribe to events.
config objectPublishable key that provides the configuration of this instance of the Truework Direct widget.
Applicant-specific token referencing the Truework Direct session created using the backend API.
Environment the session should be initialized in, one of:
Optional key-value data passed through to the widget (e.g. for internal tracking). Opaque to the widget; use at your discretion.
Optional. Defaults to true. Controls auto-complete behavior in the widget.
Truework.direct objectRepresents an initialized instance of the Truework Direct widget. This object has methods to control the widget and subscribe to widget events. All event registration methods return a function you can call to remove the listener (e.g. const removeListener = direct.onComplete(fn); removeListener();).
Truework.direct.open()Opens the widget modal window over the current page. Returns a Promise; you can await direct.open().
Truework.direct.close()Closes the widget modal window. Returns a Promise; you can await direct.close().
Truework.direct.onOpen(fn)Registers a callback to be called after the modal window is opened. Returns a function you can call to remove the listener.
Truework.direct.onClose(fn)Registers a callback to be called when the widget is closed. The callback receives a close payload object: { tasks: TaskStatus[] }. Each TaskStatus has:
completed (boolean)employer_name (string | null)task_type (string | null)Use this to show the user which tasks were completed when the widget closes. Returns a function you can call to remove the listener.
Truework.direct.onComplete(fn)Registers a callback to be called when the user has successfully completed the verification flow. Prefer this over onSuccess. Returns a function you can call to remove the listener.
Truework.direct.onSuccess(fn) (deprecated)Deprecated. Use onComplete instead. Registers a callback to be called after the flow completes successfully.
Truework.direct.onError(fn)Registers a callback to be called when an error occurs. The callback receives a TrueworkError instance (subclass of Error) with:
code — an ErrorCode value (see Error handling below)message — a string (safe for logging; PII is not exposed)name — 'TrueworkError'Returns a function you can call to remove the listener.
For advanced use, you can also subscribe with the generic on(type, handler) method for events 'open', 'close', 'complete', and 'error'.
Truework.direct.onError callbacks are called when:
There are two behavioral types:
onError is called.onError is called.The ErrorCode value on the error object obscures the root cause (preventing PII exposure) while letting you handle errors appropriately.
ErrorCode (integer enum)The error object passed to onError has a code property equal to one of:
For network errors (code === ErrorCode.Network), the widget may attach a more specific NetworkErrorCode on the error object when available, for finer-grained handling.
Example:
We do our best to support all recent versions of major browsers.
For the sake of security and providing the best experience to the majority of customers, we do not support browsers that are no longer receiving security updates and represent a small minority of traffic.
Visit our Help Center for more information.