From 1ed656cfe0decc296d0e30a47aa3357716824b00 Mon Sep 17 00:00:00 2001 From: Patrick Kubiak Date: Sat, 3 Aug 2024 09:52:10 -0400 Subject: [PATCH] Document how to customize --- docs/examples.md | 26 ++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/docs/examples.md b/docs/examples.md index cf98522..48bf557 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -42,4 +42,30 @@ exports.onExecutePostLogin = async (event, api) => { }; ``` +### Customizing Rule Callback + +The following is an example on how to use a custom Rule callback. It adds the ability to handle redirects applied to context. + +```javascript +exports.onExecutePostLogin = async (event, api) => { + const rule = accessOnWeekdaysOnly; + + // Custom rule callback + const customRuleCallback = async (obj, newUser, newContext) => { + if (obj === null) { + // Handle Redirect + if (newContext.redirect?.url) { + api.redirect.sendUserTo(newContext.redirect.url); + } + } + // Call default rule callback + await RuleToAction.defaultRuleCallback(obj, newUser, newContext); + } + + await RuleToAction.convert(event, api, rule, { + callback: customRuleCallback + }); +}; +``` + [Back to README.md](../README.md) \ No newline at end of file diff --git a/package.json b/package.json index 0383cc6..311bf32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auth0-rule-as-action", - "version": "0.3.1", + "version": "0.3.2", "description": "Run an Auth0 Rule as an Action", "author": "Patrick Kubiak ", "main": "dist/RuleToAction.js",