Skip to content

Commit

Permalink
Document how to customize
Browse files Browse the repository at this point in the history
  • Loading branch information
patkub committed Aug 3, 2024
1 parent 680ba6f commit 1ed656c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <epicpatka@gmail.com>",
"main": "dist/RuleToAction.js",
Expand Down

0 comments on commit 1ed656c

Please sign in to comment.