Skip to main content

Truework.js Credentials

The Credentials widget delivered via the Truework.js CDN.

Usage#

<script>
const { token } = await getToken(); // depends on implementation
var credentials = Truework.credentials.init({
publishableKey: 'tw_pk_gJbHD7tEwWUoZ8H_KQWKn4rEESHeNhabiosvcij9i0Q', // example key
sessionToken: token,
env: Truework.credentials.Env.Production
});
credentials.onOpen(function () {})
credentials.onClose(function () {})
credentials.onSuccess(function () {})
credentials.onError(function (e) {})
credentials.open(); // or credentials.close()
</script>

API#

init(config)#

Initializes the Credentials widget.

`config#

NameTypeDescription
publishableKeystringPublic publishable key associated with this instance of our Credentials widget
sessionTokenstringPrivate token representing the existing CredentialsSession created using our authenticated API
envEnvOptional environment the session should be initialized in — defaults to Truework.credentials.Env.Production

Returns#

Widget instance.

NameDescription
openOpens the modal
closeCloses the modal
onOpenTakes a callback function to be called after the modal is opened
onCloseTakes a callback function to be called after the modal is closed
onSuccessTakes a callback function to be called on completion
onErrorTakes a callback function to be called after an error. Receives an ErrorCode object.

Env#

Enum for available environments you can use to initialize a session.

ValueDescriptionUsage
productionProduction environmentTruework.credentials.Env.Production
sandboxSandbox environmentTruework.credentials.Env.Sandbox

Error Handling#

Error objects obscure the root cause to prevent PII leakage, and have the following shape:

{ type: 'error', code: ErrorCode }

ErrorCode#

ValueDescriptionUsagesHandling
0CriticalTruework.credentials.ErrorCode.CriticalWidget closes, calls onError handlers
1ErrorTruework.credentials.ErrorCode.ErrorWidget remains open, calls onError handlers

Usage#

credentials.onError(function (e) {
if (e.code === Truework.credentials.ErrorCode.Critical) {
// do something
}
});