@whippsp/auth0-helper 1.1.0 → 1.1.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.
- package/Auth0Helper.js +31 -7
- package/index.d.ts +14 -17
- package/package.json +1 -1
package/Auth0Helper.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
// Auth0Helper.js
|
|
2
2
|
module.exports = function(userModule, initialConfig = {}) {
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
const
|
|
3
|
+
|
|
4
|
+
// List of Auth0 Actions
|
|
5
|
+
const handlers = [
|
|
6
|
+
'onExecutePostLogin',
|
|
7
|
+
'onContinuePostLogin'
|
|
8
|
+
// Implement these later as transaction metadata is a login thing
|
|
9
|
+
// 'onExecutePostUserRegistration',
|
|
10
|
+
// 'onExecutePreUserRegistration',
|
|
11
|
+
// 'onExecutePostChangePassword',
|
|
12
|
+
// 'onExecuteCredentialsExchange'
|
|
13
|
+
];
|
|
6
14
|
|
|
7
|
-
|
|
15
|
+
handlers.forEach(handlerName => {
|
|
16
|
+
const originalHandler = userModule.exports[handlerName];
|
|
17
|
+
|
|
18
|
+
Object.defineProperty(userModule.exports, handlerName, {
|
|
8
19
|
configurable: true,
|
|
9
20
|
enumerable: true,
|
|
10
21
|
get: function() {
|
|
@@ -15,16 +26,28 @@ module.exports = function(userModule, initialConfig = {}) {
|
|
|
15
26
|
api.setHelperConfig = (newConfig) => {
|
|
16
27
|
runtimeConfig = { ...runtimeConfig, ...newConfig };
|
|
17
28
|
};
|
|
29
|
+
|
|
30
|
+
api.user.hasRole = (requestedRole) => {
|
|
31
|
+
const roles = event.authorization?.roles || [];
|
|
32
|
+
const hasIt = roles.includes(requestedRole);
|
|
33
|
+
|
|
34
|
+
log(`Checking role [${requestedRole}]: ${hasIt ? 'YES' : 'NO'}`);
|
|
35
|
+
return hasIt;
|
|
36
|
+
};
|
|
18
37
|
|
|
19
38
|
const log = (message) => {
|
|
20
39
|
if (runtimeConfig.debug === true) {
|
|
21
|
-
console.log(`[${runtimeConfig.ActionName ||
|
|
40
|
+
console.log(`[${runtimeConfig.ActionName || handlerName }] ${message}`);
|
|
22
41
|
}
|
|
23
42
|
};
|
|
24
43
|
|
|
25
44
|
if (event.transaction?.metadata?.skipremainingactions === 'true') {
|
|
26
|
-
|
|
27
|
-
|
|
45
|
+
if(runtimeConfig.ignoreskip != true)
|
|
46
|
+
{
|
|
47
|
+
log(`Skipping Action execution.`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
log(`Ignoring Skip.`);
|
|
28
51
|
}
|
|
29
52
|
|
|
30
53
|
api.skipRemaining = () => {
|
|
@@ -42,4 +65,5 @@ module.exports = function(userModule, initialConfig = {}) {
|
|
|
42
65
|
this._rawHandler = fn;
|
|
43
66
|
}
|
|
44
67
|
});
|
|
68
|
+
});
|
|
45
69
|
};
|
package/index.d.ts
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
1
|
// index.d.ts
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Configuration for the Auth0 Helper
|
|
5
|
-
*/
|
|
6
2
|
export interface HelperConfig {
|
|
7
3
|
ActionName?: string;
|
|
8
4
|
debug?: boolean;
|
|
9
5
|
}
|
|
10
6
|
|
|
11
|
-
/**
|
|
12
|
-
* Extend the global namespace to add our custom methods to the Auth0 objects
|
|
13
|
-
*/
|
|
14
7
|
declare global {
|
|
15
|
-
//
|
|
8
|
+
// This covers Post-Login
|
|
16
9
|
interface PostLoginAPI {
|
|
17
|
-
/** * Sets a metadata flag that tells all subsequent Actions in this flow to exit immediately.
|
|
18
|
-
*/
|
|
19
10
|
skipRemaining(): void;
|
|
11
|
+
setHelperConfig(config: HelperConfig): void;
|
|
12
|
+
user: {
|
|
13
|
+
hasRole(requestedRole: string): boolean;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
// This covers Post-User Registration
|
|
18
|
+
interface onContinuePostLogin {
|
|
19
|
+
skipRemaining(): void;
|
|
23
20
|
setHelperConfig(config: HelperConfig): void;
|
|
21
|
+
user: {
|
|
22
|
+
hasRole(requestedRole: string): boolean;
|
|
23
|
+
};
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
// You can add others like PreUserRegistrationAPI, etc.
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
/**
|
|
28
|
-
* The initialization function exported by the library
|
|
29
|
-
*/
|
|
30
29
|
declare function init(userModule: any, initialConfig?: HelperConfig): void;
|
|
31
|
-
|
|
32
|
-
export default init;
|
|
33
30
|
export = init;
|