@whippsp/auth0-helper 1.0.3 → 1.0.4

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 +28 -18
  2. package/package.json +1 -1
package/Auth0Helper.js CHANGED
@@ -1,24 +1,34 @@
1
1
  module.exports = function(userModule) {
2
- // Use a short delay to ensure the user has defined their exports
3
- setImmediate(() => {
4
- const original = userModule.exports.onExecutePostLogin;
5
-
6
- if (typeof original === 'function') {
7
- userModule.exports.onExecutePostLogin = async (event, api) => {
8
- // 1. Automatic skip logic
9
- if (event.transaction?.metadata?.skipremainingactions === 'true') {
10
- console.log("Skipping.");
11
- return;
12
- }
2
+ // We immediately wrap the exports object
3
+ const originalExports = userModule.exports;
13
4
 
14
- // 2. Inject your custom method directly into the api object
15
- api.skipRemaining = () => {
16
- api.transaction.setMetadata('skipremainingactions', 'true');
17
- };
5
+ userModule.exports = new Proxy(originalExports, {
6
+ get: (target, prop) => {
7
+ // We only care about intercepting the Auth0 handler
8
+ if (prop === 'onExecutePostLogin') {
9
+ const originalHandler = target[prop];
10
+
11
+ if (typeof originalHandler !== 'function') return originalHandler;
12
+
13
+ // Return the WRAPPED version of your handler
14
+ return async (event, api) => {
15
+ // 1. Check skip flag
16
+ if (event.transaction?.metadata?.skipremainingactions === 'true') {
17
+ console.log("Helper: Skipping Action");
18
+ return;
19
+ }
18
20
 
19
- // 3. Call the original code
20
- return await original(event, api);
21
- };
21
+ // 2. Inject helper method
22
+ api.skipRemaining = () => {
23
+ console.log("Helper: Setting skip flag");
24
+ api.transaction.setMetadata('skipremainingactions', 'true');
25
+ };
26
+
27
+ // 3. Execute your original code
28
+ return await originalHandler(event, api);
29
+ };
30
+ }
31
+ return target[prop];
22
32
  }
23
33
  });
24
34
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whippsp/auth0-helper",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A helper to override Auth0 Actions handlers with skip logic.",
5
5
  "main": "Auth0Helper.js",
6
6
  "publishConfig": {