@whippsp/auth0-helper 1.0.0 → 1.0.1
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 +18 -15
- package/package.json +1 -1
package/Auth0Helper.js
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
// skip-logic-lib.js
|
|
2
1
|
module.exports = function(userModule) {
|
|
3
|
-
|
|
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;
|
|
8
3
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
// Use a getter/setter on exports to "trap" the function definition
|
|
5
|
+
Object.defineProperty(userModule.exports, 'onExecutePostLogin', {
|
|
6
|
+
get: () => {
|
|
7
|
+
return async (event, api) => {
|
|
8
|
+
// 1. Logic to check skip flag
|
|
12
9
|
if (event.transaction?.metadata?.skipremainingactions === 'true') {
|
|
13
|
-
|
|
14
|
-
return;
|
|
10
|
+
return;
|
|
15
11
|
}
|
|
16
12
|
|
|
17
|
-
// 2.
|
|
13
|
+
// 2. Inject the helper
|
|
18
14
|
api.skipRemaining = () => {
|
|
19
15
|
api.transaction.setMetadata('skipremainingactions', 'true');
|
|
20
16
|
};
|
|
21
17
|
|
|
22
|
-
// 3. Run original logic
|
|
23
|
-
|
|
18
|
+
// 3. Run original logic if it exists
|
|
19
|
+
if (originalHandler) {
|
|
20
|
+
return await originalHandler(event, api);
|
|
21
|
+
}
|
|
24
22
|
};
|
|
25
|
-
}
|
|
23
|
+
},
|
|
24
|
+
set: (value) => {
|
|
25
|
+
originalHandler = value; // Capture the user's function
|
|
26
|
+
},
|
|
27
|
+
configurable: true,
|
|
28
|
+
enumerable: true
|
|
26
29
|
});
|
|
27
30
|
};
|