loading
Preparing LoginRadius developer resources
Mission: Help enterprises accelerate digital transformation with our fully-managed Customer IAM technology.
Skip to main content

Hook API

hook is the second argument passed to every exports.execute function. It provides methods to write output from your script: custom identity fields, token claims, metadata, errors, and shared state.

exports.execute = async (lrObject, hook) => {
// use hook.* methods to write output
};

Method Reference

1. hook.identity.setCustomField(key, value)

Sets a custom field on the user's identity profile.

  • key must be a string: type error otherwise.
  • value can be any serialisable value.
hook.identity.setCustomField("LastLoginDate", new Date().toISOString());

2. hook.identity.setMetaData(key, value)

Sets a metadata flag on the user's identity. Only the following keys are supported:

KeyType
EmailVerifiedboolean
IsLoginLockedboolean
DisableLoginboolean
IsActiveboolean
hook.identity.setMetaData("IsLoginLocked", true);

3. hook.accessToken.setCustomClaim(claim, value)

Injects a custom claim into the user's access token.

  • Both claim and value must be strings: type error otherwise.
hook.accessToken.setCustomClaim("role", "admin");
hook.accessToken.setCustomClaim("plan", "enterprise");

4. hook.idToken.setCustomClaim(claim, value)

Injects a custom claim into the user's ID token.

  • Both claim and value must be strings: type error otherwise.
hook.idToken.setCustomClaim("sca_verified", "true");
hook.idToken.setCustomClaim("risk_score", "12");

5. hook.sharedState.set(key, value)

Writes a key-value pair into the workflow's SharedState, making it available to downstream nodes.

  • Both key and value must be strings.
  • In SCA flows, values written here are available in Send Push Notification message templates as {{sharedstate.key}}.
hook.sharedState.set("verified_amount", "89.99");
hook.sharedState.set("verified_currency", "USD");
hook.sharedState.set("verified_payee", "ShopCase");
hook.sharedState.set("sca_verified", "true");

6. hook.setError(code, message, description)

Sets a user-facing error that short-circuits the workflow. The workflow follows the matching error-code output edge on the Script node.

  • code: integer error code.
  • message: short error string.
  • description: longer explanation.
hook.setError(145, "You can't log in with Gmail", "Please use your work email to log in.");

Type Errors

Each method validates its argument types at runtime. Passing a wrong type produces a descriptive error:

MethodError
setCustomClaimType error in setCustomClaim
setCustomFieldType error in setCustomField
setMetaDataType error in setMetaData
setErrorType error in setError

Related