@whippsp/auth0-helper 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/Auth0Helper.js +22 -15
  2. package/package.json +1 -1
package/Auth0Helper.js CHANGED
@@ -1,27 +1,34 @@
1
- // skip-logic-lib.js
2
1
  module.exports = function(userModule) {
3
- // We use a getter/setter approach or a simple timeout to ensure
4
- // we catch the export even if the user defines it AFTER requiring your lib.
5
-
6
- process.nextTick(() => {
7
- const originalHandler = userModule.exports.onExecutePostLogin;
2
+ let originalHandler = null;
3
+ console.log("Auth0Help0er module started");
8
4
 
9
- if (typeof originalHandler === 'function') {
10
- userModule.exports.onExecutePostLogin = async (event, api) => {
11
- // 1. Check for skip flag
5
+ // Use a getter/setter on exports to "trap" the function definition
6
+ Object.defineProperty(userModule.exports, 'onExecutePostLogin', {
7
+ get: () => {
8
+ return async (event, api) => {
9
+ console.log("Auth0Help0er module override.");
10
+
11
+ // 1. Logic to check skip flag
12
12
  if (event.transaction?.metadata?.skipremainingactions === 'true') {
13
- console.log("Action skipped by library.");
14
- return;
13
+ console.log("Skipping");
14
+ return;
15
15
  }
16
16
 
17
- // 2. Add helper to api object
17
+ // 2. Inject the helper
18
18
  api.skipRemaining = () => {
19
19
  api.transaction.setMetadata('skipremainingactions', 'true');
20
20
  };
21
21
 
22
- // 3. Run original logic
23
- return await originalHandler(event, api);
22
+ // 3. Run original logic if it exists
23
+ if (originalHandler) {
24
+ return await originalHandler(event, api);
25
+ }
24
26
  };
25
- }
27
+ },
28
+ set: (value) => {
29
+ originalHandler = value; // Capture the user's function
30
+ },
31
+ configurable: true,
32
+ enumerable: true
26
33
  });
27
34
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whippsp/auth0-helper",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A helper to override Auth0 Actions handlers with skip logic.",
5
5
  "main": "Auth0Helper.js",
6
6
  "publishConfig": {