@whippsp/auth0-helper 1.0.2 → 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.
- package/Auth0Helper.js +26 -26
- package/package.json +1 -1
package/Auth0Helper.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
module.exports = function(userModule) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
// We immediately wrap the exports object
|
|
3
|
+
const originalExports = userModule.exports;
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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;
|
|
10
12
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
}
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
// 2. Inject helper method
|
|
22
|
+
api.skipRemaining = () => {
|
|
23
|
+
console.log("Helper: Setting skip flag");
|
|
24
|
+
api.transaction.setMetadata('skipremainingactions', 'true');
|
|
25
|
+
};
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
if (originalHandler) {
|
|
27
|
+
// 3. Execute your original code
|
|
24
28
|
return await originalHandler(event, api);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
originalHandler = value; // Capture the user's function
|
|
30
|
-
},
|
|
31
|
-
configurable: true,
|
|
32
|
-
enumerable: true
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return target[prop];
|
|
32
|
+
}
|
|
33
33
|
});
|
|
34
34
|
};
|