@whippsp/auth0-helper 1.0.4 → 1.0.6
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 +27 -27
- package/package.json +1 -1
package/Auth0Helper.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
+
// Auth0Helper.js
|
|
1
2
|
module.exports = function(userModule) {
|
|
2
|
-
|
|
3
|
-
const originalExports = userModule.exports;
|
|
3
|
+
let originalHandler = null;
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (typeof originalHandler !== 'function') return originalHandler;
|
|
5
|
+
// We define a getter/setter on the EXISTING exports object
|
|
6
|
+
Object.defineProperty(userModule.exports, 'onExecutePostLogin', {
|
|
7
|
+
get: () => {
|
|
8
|
+
// If the user hasn't defined the function yet, return undefined
|
|
9
|
+
if (typeof originalHandler !== 'function') return originalHandler;
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
// Return our intercepted version
|
|
12
|
+
return async (event, api) => {
|
|
13
|
+
// 1. Automatic skip check
|
|
14
|
+
if (event.transaction?.metadata?.skipremainingactions === 'true') {
|
|
15
|
+
console.log("Auth0Helper: Skipping Action");
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
api.transaction.setMetadata('skipremainingactions', 'true');
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// 3. Execute your original code
|
|
28
|
-
return await originalHandler(event, api);
|
|
19
|
+
// 2. Inject the method
|
|
20
|
+
api.skipRemaining = () => {
|
|
21
|
+
api.transaction.setMetadata('skipremainingactions', 'true');
|
|
29
22
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
|
|
24
|
+
// 3. Call the actual code
|
|
25
|
+
return await originalHandler(event, api);
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
set: (value) => {
|
|
29
|
+
originalHandler = value; // Capture the user's function when they assign it
|
|
30
|
+
},
|
|
31
|
+
configurable: true,
|
|
32
|
+
enumerable: true
|
|
33
33
|
});
|
|
34
34
|
};
|