@whippsp/auth0-helper 1.1.3 → 1.1.5
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 +10 -8
- package/index.d.ts +13 -13
- package/package.json +1 -1
package/Auth0Helper.js
CHANGED
|
@@ -27,14 +27,16 @@ module.exports = function(userModule, initialConfig = {}) {
|
|
|
27
27
|
runtimeConfig = { ...runtimeConfig, ...newConfig };
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
api.user
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
if (api.user) {
|
|
31
|
+
api.user.hasRole = (requestedRole) => {
|
|
32
|
+
const roles = event.authorization?.roles || [];
|
|
33
|
+
const hasIt = roles.includes(requestedRole);
|
|
34
|
+
|
|
35
|
+
log(`Checking role [${requestedRole}]: ${hasIt ? 'YES' : 'NO'}`);
|
|
36
|
+
return hasIt;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
38
40
|
const log = (message) => {
|
|
39
41
|
if (runtimeConfig.debug === true) {
|
|
40
42
|
console.log(`[${runtimeConfig.ActionName || handlerName }] ${message}`);
|
package/index.d.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
// index.d.ts
|
|
2
2
|
export interface HelperConfig {
|
|
3
|
+
/** The name used in logs. Defaults to the Action handler name. */
|
|
3
4
|
ActionName?: string;
|
|
5
|
+
/** If true, enables console logging for helper events. */
|
|
4
6
|
debug?: boolean;
|
|
5
7
|
}
|
|
6
8
|
|
|
7
9
|
declare global {
|
|
8
|
-
|
|
10
|
+
// 1. Correctly augment the UserAPI interface
|
|
11
|
+
// This adds the method to the 'api.user' object globally
|
|
9
12
|
interface UserAPI {
|
|
10
|
-
/** * Returns true if the user has the specified Auth0 Role
|
|
13
|
+
/** * Returns true if the user has the specified Auth0 Role.
|
|
14
|
+
* @param roleName The exact name of the role to check.
|
|
11
15
|
*/
|
|
12
16
|
hasRole(roleName: string): boolean;
|
|
13
17
|
}
|
|
14
|
-
|
|
15
|
-
// This covers Post-Login
|
|
18
|
+
|
|
16
19
|
interface PostLoginAPI {
|
|
17
20
|
skipRemaining(): void;
|
|
18
21
|
setHelperConfig(config: HelperConfig): void;
|
|
19
|
-
user: {
|
|
20
|
-
hasRole(requestedRole: string): boolean;
|
|
21
|
-
};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
interface onContinuePostLogin {
|
|
24
|
+
interface PostUserRegistrationAPI {
|
|
26
25
|
skipRemaining(): void;
|
|
27
26
|
setHelperConfig(config: HelperConfig): void;
|
|
28
|
-
user: {
|
|
29
|
-
hasRole(requestedRole: string): boolean;
|
|
30
|
-
};
|
|
31
27
|
}
|
|
32
28
|
|
|
33
|
-
//
|
|
29
|
+
// Auth0 uses this specific interface name for the Continue flow
|
|
30
|
+
interface PostLoginContinueAPI {
|
|
31
|
+
skipRemaining(): void;
|
|
32
|
+
setHelperConfig(config: HelperConfig): void;
|
|
33
|
+
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
declare function init(userModule: any, initialConfig?: HelperConfig): void;
|