Skip to content

Commit afcaf55

Browse files
authored
inject management key as token (#560)
* inject management key as token * CR fixes
1 parent ed76054 commit afcaf55

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ type JWTResponseWithCookies = CoreJWTResponse & {
3333
/** Configuration arguments which include the Descope core SDK args and an optional management key */
3434
type NodeSdkArgs = Parameters<typeof createSdk>[0] & {
3535
managementKey?: string;
36+
authManagementKey?: string;
3637
publicKey?: string;
3738
};
3839

39-
const nodeSdk = ({ managementKey, publicKey, ...config }: NodeSdkArgs) => {
40+
const nodeSdk = ({ authManagementKey, managementKey, publicKey, ...config }: NodeSdkArgs) => {
4041
const coreSdk = createSdk({
4142
fetch,
4243
...config,
@@ -46,6 +47,19 @@ const nodeSdk = ({ managementKey, publicKey, ...config }: NodeSdkArgs) => {
4647
'x-descope-sdk-node-version': process?.versions?.node || '',
4748
'x-descope-sdk-version': BUILD_VERSION,
4849
},
50+
hooks: {
51+
...config.hooks,
52+
beforeRequest: [
53+
(requestConfig) => {
54+
if (!requestConfig.token && authManagementKey) {
55+
// eslint-disable-next-line no-param-reassign
56+
requestConfig.token = authManagementKey;
57+
}
58+
59+
return requestConfig;
60+
},
61+
].concat(config.hooks?.beforeRequest || []),
62+
},
4963
});
5064

5165
const { projectId, logger } = config;

0 commit comments

Comments
 (0)