@descope/nextjs-sdk 0.0.0-alpha.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/LICENSE +21 -0
- package/README.md +493 -0
- package/dist/cjs/client/index.js +52 -0
- package/dist/cjs/client/index.js.map +1 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/server/authMiddleware.js +97 -0
- package/dist/cjs/server/authMiddleware.js.map +1 -0
- package/dist/cjs/server/constants.js +16 -0
- package/dist/cjs/server/constants.js.map +1 -0
- package/dist/cjs/server/index.js +13 -0
- package/dist/cjs/server/index.js.map +1 -0
- package/dist/cjs/server/logger.js +28 -0
- package/dist/cjs/server/logger.js.map +1 -0
- package/dist/cjs/server/sdk.js +29 -0
- package/dist/cjs/server/sdk.js.map +1 -0
- package/dist/cjs/server/session.js +62 -0
- package/dist/cjs/server/session.js.map +1 -0
- package/dist/cjs/server/utils.js +24 -0
- package/dist/cjs/server/utils.js.map +1 -0
- package/dist/cjs/shared/AuthProvider.js +15 -0
- package/dist/cjs/shared/AuthProvider.js.map +1 -0
- package/dist/cjs/shared/DescopeFlows.js +50 -0
- package/dist/cjs/shared/DescopeFlows.js.map +1 -0
- package/dist/cjs/shared/DescopeWidgets.js +27 -0
- package/dist/cjs/shared/DescopeWidgets.js.map +1 -0
- package/dist/cjs/shared/constants.js +10 -0
- package/dist/cjs/shared/constants.js.map +1 -0
- package/dist/client/dts/src/client/index.d.ts +12 -0
- package/dist/client/dts/src/index.d.ts +1 -0
- package/dist/client/dts/src/server/authMiddleware.d.ts +12 -0
- package/dist/client/dts/src/server/constants.d.ts +9 -0
- package/dist/client/dts/src/server/index.d.ts +3 -0
- package/dist/client/dts/src/server/sdk.d.ts +10 -0
- package/dist/client/dts/src/server/session.d.ts +6 -0
- package/dist/client/dts/src/server/utils.d.ts +1 -0
- package/dist/client/dts/src/shared/AuthProvider.d.ts +3 -0
- package/dist/client/dts/src/shared/DescopeFlows.d.ts +130 -0
- package/dist/client/dts/src/shared/DescopeWidgets.d.ts +72 -0
- package/dist/client/dts/src/shared/constants.d.ts +4 -0
- package/dist/client/dts/src/shared/index.d.ts +3 -0
- package/dist/client/dts/src/types.d.ts +1 -0
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.js +14 -0
- package/dist/client/index.js.map +1 -0
- package/dist/dts/src/client/index.d.ts +12 -0
- package/dist/dts/src/index.d.ts +1 -0
- package/dist/dts/src/server/authMiddleware.d.ts +12 -0
- package/dist/dts/src/server/constants.d.ts +9 -0
- package/dist/dts/src/server/index.d.ts +3 -0
- package/dist/dts/src/server/sdk.d.ts +10 -0
- package/dist/dts/src/server/session.d.ts +6 -0
- package/dist/dts/src/server/utils.d.ts +1 -0
- package/dist/dts/src/shared/AuthProvider.d.ts +3 -0
- package/dist/dts/src/shared/DescopeFlows.d.ts +130 -0
- package/dist/dts/src/shared/DescopeWidgets.d.ts +72 -0
- package/dist/dts/src/shared/constants.d.ts +4 -0
- package/dist/dts/src/shared/index.d.ts +3 -0
- package/dist/dts/src/types.d.ts +1 -0
- package/dist/esm/client/index.js +3 -0
- package/dist/esm/client/index.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/server/authMiddleware.js +95 -0
- package/dist/esm/server/authMiddleware.js.map +1 -0
- package/dist/esm/server/constants.js +12 -0
- package/dist/esm/server/constants.js.map +1 -0
- package/dist/esm/server/index.js +4 -0
- package/dist/esm/server/index.js.map +1 -0
- package/dist/esm/server/logger.js +25 -0
- package/dist/esm/server/logger.js.map +1 -0
- package/dist/esm/server/sdk.js +26 -0
- package/dist/esm/server/sdk.js.map +1 -0
- package/dist/esm/server/session.js +59 -0
- package/dist/esm/server/session.js.map +1 -0
- package/dist/esm/server/utils.js +22 -0
- package/dist/esm/server/utils.js.map +1 -0
- package/dist/esm/shared/AuthProvider.js +13 -0
- package/dist/esm/shared/AuthProvider.js.map +1 -0
- package/dist/esm/shared/DescopeFlows.js +45 -0
- package/dist/esm/shared/DescopeFlows.js.map +1 -0
- package/dist/esm/shared/DescopeWidgets.js +20 -0
- package/dist/esm/shared/DescopeWidgets.js.map +1 -0
- package/dist/esm/shared/constants.js +8 -0
- package/dist/esm/shared/constants.js.map +1 -0
- package/dist/index.d.ts +212 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/server/authMiddleware.js +98 -0
- package/dist/server/authMiddleware.js.map +1 -0
- package/dist/server/constants.js +12 -0
- package/dist/server/constants.js.map +1 -0
- package/dist/server/dts/src/client/index.d.ts +12 -0
- package/dist/server/dts/src/index.d.ts +1 -0
- package/dist/server/dts/src/server/authMiddleware.d.ts +12 -0
- package/dist/server/dts/src/server/constants.d.ts +9 -0
- package/dist/server/dts/src/server/index.d.ts +3 -0
- package/dist/server/dts/src/server/sdk.d.ts +10 -0
- package/dist/server/dts/src/server/session.d.ts +6 -0
- package/dist/server/dts/src/server/utils.d.ts +1 -0
- package/dist/server/dts/src/shared/AuthProvider.d.ts +3 -0
- package/dist/server/dts/src/shared/DescopeFlows.d.ts +130 -0
- package/dist/server/dts/src/shared/DescopeWidgets.d.ts +72 -0
- package/dist/server/dts/src/shared/constants.d.ts +4 -0
- package/dist/server/dts/src/shared/index.d.ts +3 -0
- package/dist/server/dts/src/types.d.ts +1 -0
- package/dist/server/index.d.ts +32 -0
- package/dist/server/index.js +4 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/sdk.js +27 -0
- package/dist/server/sdk.js.map +1 -0
- package/dist/server/session.js +32 -0
- package/dist/server/session.js.map +1 -0
- package/dist/server/utils.js +22 -0
- package/dist/server/utils.js.map +1 -0
- package/dist/shared/AuthProvider.js +19 -0
- package/dist/shared/AuthProvider.js.map +1 -0
- package/dist/shared/DescopeFlows.js +53 -0
- package/dist/shared/DescopeFlows.js.map +1 -0
- package/dist/shared/DescopeWidgets.js +35 -0
- package/dist/shared/DescopeWidgets.js.map +1 -0
- package/dist/shared/constants.js +8 -0
- package/dist/shared/constants.js.map +1 -0
- package/dist/types/client/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/server/authMiddleware.d.ts +12 -0
- package/dist/types/server/constants.d.ts +9 -0
- package/dist/types/server/index.d.ts +3 -0
- package/dist/types/server/logger.d.ts +25 -0
- package/dist/types/server/sdk.d.ts +9 -0
- package/dist/types/server/session.d.ts +10 -0
- package/dist/types/server/utils.d.ts +1 -0
- package/dist/types/shared/AuthProvider.d.ts +3 -0
- package/dist/types/shared/DescopeFlows.d.ts +141 -0
- package/dist/types/shared/DescopeWidgets.d.ts +54 -0
- package/dist/types/shared/constants.d.ts +4 -0
- package/dist/types/shared/index.d.ts +3 -0
- package/dist/types/types.d.ts +1 -0
- package/package.json +152 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
/*
|
|
3
|
+
Merges multiple search params into one.
|
|
4
|
+
It will override according to the order of the search params
|
|
5
|
+
Examples:
|
|
6
|
+
- mergeSearchParams('?a=1', '?b=2') => 'a=1&b=2'
|
|
7
|
+
- mergeSearchParams('?a=1', '?a=2') => 'a=2'
|
|
8
|
+
- mergeSearchParams('?a=1', '?a=2', '?b=3') => 'a=2&b=3'
|
|
9
|
+
*/
|
|
10
|
+
const mergeSearchParams = (...searchParams) => {
|
|
11
|
+
const res = searchParams.reduce((acc, curr) => {
|
|
12
|
+
const currParams = new URLSearchParams(curr);
|
|
13
|
+
currParams.forEach((value, key) => {
|
|
14
|
+
acc.set(key, value);
|
|
15
|
+
});
|
|
16
|
+
return acc;
|
|
17
|
+
}, new URLSearchParams());
|
|
18
|
+
return res.toString();
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { mergeSearchParams };
|
|
22
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/server/utils.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\n\n/*\nMerges multiple search params into one.\nIt will override according to the order of the search params\nExamples:\n - mergeSearchParams('?a=1', '?b=2') => 'a=1&b=2'\n - mergeSearchParams('?a=1', '?a=2') => 'a=2'\n - mergeSearchParams('?a=1', '?a=2', '?b=3') => 'a=2&b=3'\n*/\nexport const mergeSearchParams = (...searchParams: string[]): string => {\n\tconst res = searchParams.reduce((acc, curr) => {\n\t\tconst currParams = new URLSearchParams(curr);\n\t\tcurrParams.forEach((value, key) => {\n\t\t\tacc.set(key, value);\n\t\t});\n\t\treturn acc;\n\t}, new URLSearchParams());\n\n\treturn res.toString();\n};\n"],"names":[],"mappings":"AAAA;AAEA;;;;;;;AAOE;MACW,iBAAiB,GAAG,CAAC,GAAG,YAAsB,KAAY;IACtE,MAAM,GAAG,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,KAAI;AAC7C,QAAA,MAAM,UAAU,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QAC7C,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,KAAI;AACjC,YAAA,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACrB,SAAC,CAAC,CAAC;AACH,QAAA,OAAO,GAAG,CAAC;AACZ,KAAC,EAAE,IAAI,eAAe,EAAE,CAAC,CAAC;AAE1B,IAAA,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACvB;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { baseHeaders, AuthProvider as AuthProvider$1 } from '@descope/react-sdk';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { baseHeaders as baseHeaders$1 } from './constants.js';
|
|
5
|
+
|
|
6
|
+
// Override baseHeaders
|
|
7
|
+
Object.assign(baseHeaders, baseHeaders$1);
|
|
8
|
+
const AuthProvider = ({ ...props }) => (
|
|
9
|
+
// by default we use sessionTokenViaCookie, so middleware will work out of the box
|
|
10
|
+
React.createElement(AuthProvider$1, { sessionTokenViaCookie: true, ...props }));
|
|
11
|
+
|
|
12
|
+
export { AuthProvider as default };
|
|
13
|
+
//# sourceMappingURL=AuthProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthProvider.js","sources":["../../../src/shared/AuthProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n\tAuthProvider as AuthProviderComp,\n\tbaseHeaders\n} from '@descope/react-sdk';\nimport React from 'react';\nimport { baseHeaders as nextBaseHeaders } from './constants';\n\n// Override baseHeaders\nObject.assign(baseHeaders, nextBaseHeaders);\n\nconst AuthProvider: typeof AuthProviderComp = ({ ...props }) => (\n\t// by default we use sessionTokenViaCookie, so middleware will work out of the box\n\t<AuthProviderComp sessionTokenViaCookie {...props} />\n);\n\nexport default AuthProvider;\n"],"names":[],"mappings":";;;;;AASA;AACA;AAEM;AACL;AACA;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import dynamic from 'next/dynamic.js';
|
|
4
|
+
import { useRouter } from 'next/navigation.js';
|
|
5
|
+
import { baseHeaders } from './constants.js';
|
|
6
|
+
|
|
7
|
+
// Generalized function to dynamically import components from @descope/react-sdk
|
|
8
|
+
// Dynamic is needed because the Descope components has a side effect us
|
|
9
|
+
// and NextJS will load the page on the server even if it is a client side only page
|
|
10
|
+
const dynamicDescopeComponent = (componentName) => dynamic(async () => {
|
|
11
|
+
const DescopeComponents = await import('@descope/react-sdk');
|
|
12
|
+
// Override baseHeaders
|
|
13
|
+
Object.assign(DescopeComponents.baseHeaders, baseHeaders);
|
|
14
|
+
const Component = DescopeComponents[componentName];
|
|
15
|
+
return ({ redirectAfterSuccess = '', redirectAfterError = '', ...props }) => {
|
|
16
|
+
const router = useRouter();
|
|
17
|
+
const modifiedProps = { ...props };
|
|
18
|
+
if (redirectAfterSuccess) {
|
|
19
|
+
modifiedProps.onSuccess = (...args) => {
|
|
20
|
+
if (props.onSuccess) {
|
|
21
|
+
props.onSuccess(...args);
|
|
22
|
+
}
|
|
23
|
+
router.push(redirectAfterSuccess);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (redirectAfterError) {
|
|
27
|
+
modifiedProps.onError = (...args) => {
|
|
28
|
+
if (props.onError) {
|
|
29
|
+
props.onError(...args);
|
|
30
|
+
}
|
|
31
|
+
router.push(redirectAfterError);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return React.createElement(Component, { ...modifiedProps });
|
|
35
|
+
};
|
|
36
|
+
}, {
|
|
37
|
+
ssr: false
|
|
38
|
+
});
|
|
39
|
+
const Descope = dynamicDescopeComponent('Descope');
|
|
40
|
+
const SignInFlow = dynamicDescopeComponent('SignInFlow');
|
|
41
|
+
const SignUpFlow = dynamicDescopeComponent('SignUpFlow');
|
|
42
|
+
const SignUpOrInFlow = dynamicDescopeComponent('SignUpOrInFlow');
|
|
43
|
+
|
|
44
|
+
export { Descope, SignInFlow, SignUpFlow, SignUpOrInFlow };
|
|
45
|
+
//# sourceMappingURL=DescopeFlows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DescopeFlows.js","sources":["../../../src/shared/DescopeFlows.tsx"],"sourcesContent":["'use client';\n\n// workaround for TS issue https://github.com/microsoft/TypeScript/issues/42873\n// eslint-disable-next-line\nimport type * as _1 from '@descope/react-sdk/node_modules/@types/react';\n// eslint-disable-next-line\nimport type * as _2 from '@descope/react-sdk/node_modules/@descope/web-component/dist';\n\nimport React, { ComponentType, ComponentProps } from 'react';\nimport dynamic from 'next/dynamic';\nimport { useRouter } from 'next/navigation';\nimport {\n\tDescope as DescopeWC,\n\tSignInFlow as SignInFlowWC,\n\tSignUpFlow as SignUpFlowWC,\n\tSignUpOrInFlow as SignUpOrInFlowWC\n} from '@descope/react-sdk';\nimport { baseHeaders as nextBaseHeaders } from './constants';\n\ntype DescopeWCProps = ComponentProps<typeof DescopeWC>;\ntype SignInFlowProps = ComponentProps<typeof SignInFlowWC>;\ntype SignUpFlowProps = ComponentProps<typeof SignUpFlowWC>;\ntype SignUpOrInFlowProps = ComponentProps<typeof SignUpOrInFlowWC>;\n\ntype AdditionalProps = {\n\tredirectAfterSuccess?: string;\n\tredirectAfterError?: string;\n};\n\ntype DynamicComponentProps = {\n\tonSuccess?: (...args: any[]) => void;\n\tonError?: (...args: any[]) => void;\n};\n\n// Generalized function to dynamically import components from @descope/react-sdk\n// Dynamic is needed because the Descope components has a side effect us\n// and NextJS will load the page on the server even if it is a client side only page\nconst dynamicDescopeComponent = <\n\tT extends ComponentType<DynamicComponentProps>\n>(\n\tcomponentName: string\n) =>\n\tdynamic<ComponentProps<T> & AdditionalProps>(\n\t\tasync () => {\n\t\t\tconst DescopeComponents = await import('@descope/react-sdk');\n\n\t\t\t// Override baseHeaders\n\t\t\tObject.assign(DescopeComponents.baseHeaders, nextBaseHeaders);\n\n\t\t\tconst Component = DescopeComponents[componentName];\n\t\t\treturn ({\n\t\t\t\tredirectAfterSuccess = '',\n\t\t\t\tredirectAfterError = '',\n\t\t\t\t...props\n\t\t\t}: ComponentProps<T> & AdditionalProps) => {\n\t\t\t\tconst router = useRouter();\n\t\t\t\tconst modifiedProps = { ...props };\n\n\t\t\t\tif (redirectAfterSuccess) {\n\t\t\t\t\tmodifiedProps.onSuccess = (...args) => {\n\t\t\t\t\t\tif (props.onSuccess) {\n\t\t\t\t\t\t\tprops.onSuccess(...args);\n\t\t\t\t\t\t}\n\t\t\t\t\t\trouter.push(redirectAfterSuccess);\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (redirectAfterError) {\n\t\t\t\t\tmodifiedProps.onError = (...args) => {\n\t\t\t\t\t\tif (props.onError) {\n\t\t\t\t\t\t\tprops.onError(...args);\n\t\t\t\t\t\t}\n\t\t\t\t\t\trouter.push(redirectAfterError);\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn <Component {...modifiedProps} />;\n\t\t\t};\n\t\t},\n\t\t{\n\t\t\tssr: false\n\t\t}\n\t);\n\nexport const Descope =\n\tdynamicDescopeComponent<React.ComponentType<DescopeWCProps>>('Descope');\nexport const SignInFlow =\n\tdynamicDescopeComponent<React.ComponentType<SignInFlowProps>>('SignInFlow');\nexport const SignUpFlow =\n\tdynamicDescopeComponent<React.ComponentType<SignUpFlowProps>>('SignUpFlow');\nexport const SignUpOrInFlow =\n\tdynamicDescopeComponent<React.ComponentType<SignUpOrInFlowProps>>(\n\t\t'SignUpOrInFlow'\n\t);\n"],"names":[],"mappings":";;;;;;AAkCA;AACA;AACA;AACA;AAOG;;;AAKA;AACA;AAKC;AACA;;AAGC;AACC;AACC;;AAED;AACD;;;AAIA;AACC;AACC;;AAED;AACD;;AAED;AACD;AACD;AAEC;AACA;;;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import dynamic from 'next/dynamic.js';
|
|
3
|
+
import { UserManagement as UserManagement$1, RoleManagement as RoleManagement$1, AccessKeyManagement as AccessKeyManagement$1, AuditManagement as AuditManagement$1, UserProfile as UserProfile$1, ApplicationsPortal as ApplicationsPortal$1 } from '@descope/react-sdk';
|
|
4
|
+
|
|
5
|
+
// a helper function to dynamically load the components
|
|
6
|
+
// This function prevents Next.js from trying to server-side render these components
|
|
7
|
+
// Update the helper function to use generics for preserving component prop types
|
|
8
|
+
const dynamicWidgetComponent = (Component) => dynamic(() => Promise.resolve(Component), {
|
|
9
|
+
ssr: false // Disable server-side rendering for this component
|
|
10
|
+
});
|
|
11
|
+
// Use the helper function to create dynamically loaded components
|
|
12
|
+
const UserManagement = dynamicWidgetComponent(UserManagement$1);
|
|
13
|
+
const RoleManagement = dynamicWidgetComponent(RoleManagement$1);
|
|
14
|
+
const AccessKeyManagement = dynamicWidgetComponent(AccessKeyManagement$1);
|
|
15
|
+
const AuditManagement = dynamicWidgetComponent(AuditManagement$1);
|
|
16
|
+
const UserProfile = dynamicWidgetComponent(UserProfile$1);
|
|
17
|
+
const ApplicationsPortal = dynamicWidgetComponent(ApplicationsPortal$1);
|
|
18
|
+
|
|
19
|
+
export { AccessKeyManagement, ApplicationsPortal, AuditManagement, RoleManagement, UserManagement, UserProfile };
|
|
20
|
+
//# sourceMappingURL=DescopeWidgets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DescopeWidgets.js","sources":["../../../src/shared/DescopeWidgets.tsx"],"sourcesContent":["'use client';\n\n// eslint-disable-next-line\nimport type * as _1 from '@descope/react-sdk/node_modules/@types/react';\n\nimport { ComponentType } from 'react';\nimport dynamic from 'next/dynamic';\nimport {\n\tUserManagement as UserManagementWC,\n\tRoleManagement as RoleManagementWC,\n\tAccessKeyManagement as AccessKeyManagementWC,\n\tAuditManagement as AuditManagementWC,\n\tUserProfile as UserProfileWc,\n\tApplicationsPortal as ApplicationsPortalWc\n} from '@descope/react-sdk';\n\n// a helper function to dynamically load the components\n// This function prevents Next.js from trying to server-side render these components\n// Update the helper function to use generics for preserving component prop types\nconst dynamicWidgetComponent = <P extends {}>(Component: ComponentType<P>) =>\n\tdynamic<P>(() => Promise.resolve(Component), {\n\t\tssr: false // Disable server-side rendering for this component\n\t});\n\n// Use the helper function to create dynamically loaded components\nexport const UserManagement = dynamicWidgetComponent(UserManagementWC);\nexport const RoleManagement = dynamicWidgetComponent(RoleManagementWC);\nexport const AccessKeyManagement = dynamicWidgetComponent(\n\tAccessKeyManagementWC\n);\nexport const AuditManagement = dynamicWidgetComponent(AuditManagementWC);\nexport const UserProfile = dynamicWidgetComponent(UserProfileWc);\nexport const ApplicationsPortal = dynamicWidgetComponent(ApplicationsPortalWc);\n"],"names":[],"mappings":";;;;AAgBA;AACA;AACA;AACA;;AAGE;AAEF;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../src/shared/constants.ts"],"sourcesContent":["// Replaced in build time\ndeclare const BUILD_VERSION: string;\n\n// eslint-disable-next-line import/prefer-default-export\nexport const baseHeaders = {\n\t'x-descope-sdk-name': 'nextjs',\n\t'x-descope-sdk-version': BUILD_VERSION\n};\n"],"names":[],"mappings":"AAGA;AACa,MAAA,WAAW,GAAG;AAC1B,IAAA,oBAAoB,EAAE,QAAQ;AAC9B,IAAA,uBAAuB,EAAE,eAAa;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AuthProvider as AuthProvider$1 } from '@descope/react-sdk';
|
|
3
|
+
import * as _descope_core_js_sdk from '@descope/core-js-sdk';
|
|
4
|
+
import * as _1 from '@descope/react-sdk/node_modules/@types/react';
|
|
5
|
+
import * as _2 from '@descope/react-sdk/node_modules/@descope/web-component/dist';
|
|
6
|
+
import * as _descope_web_component from '@descope/web-component';
|
|
7
|
+
|
|
8
|
+
declare const AuthProvider: typeof AuthProvider$1;
|
|
9
|
+
|
|
10
|
+
type AdditionalProps = {
|
|
11
|
+
redirectAfterSuccess?: string;
|
|
12
|
+
redirectAfterError?: string;
|
|
13
|
+
};
|
|
14
|
+
declare const Descope: _1.ComponentType<
|
|
15
|
+
{
|
|
16
|
+
flowId: string;
|
|
17
|
+
onSuccess?: (e: CustomEvent<_descope_core_js_sdk.JWTResponse>) => void;
|
|
18
|
+
onError?: (
|
|
19
|
+
e: CustomEvent<{
|
|
20
|
+
errorCode: string;
|
|
21
|
+
errorDescription: string;
|
|
22
|
+
errorMessage?: string;
|
|
23
|
+
retryAfter?: string;
|
|
24
|
+
}>
|
|
25
|
+
) => void;
|
|
26
|
+
onReady?: (e: CustomEvent<{}>) => void;
|
|
27
|
+
logger?: Partial<any>;
|
|
28
|
+
tenant?: string;
|
|
29
|
+
theme?: _2.ThemeOptions;
|
|
30
|
+
locale?: string;
|
|
31
|
+
autoFocus?: _2.AutoFocusOptions;
|
|
32
|
+
validateOnBlur?: boolean;
|
|
33
|
+
restartOnError?: boolean;
|
|
34
|
+
debug?: boolean;
|
|
35
|
+
telemetryKey?: string;
|
|
36
|
+
redirectUrl?: string;
|
|
37
|
+
errorTransformer?: (error: { text: string; type: string }) => string;
|
|
38
|
+
form?: Record<string, any>;
|
|
39
|
+
client?: Record<string, any>;
|
|
40
|
+
styleId?: string;
|
|
41
|
+
} & _1.RefAttributes<HTMLElement> &
|
|
42
|
+
AdditionalProps
|
|
43
|
+
>;
|
|
44
|
+
declare const SignInFlow: _1.ComponentType<
|
|
45
|
+
{
|
|
46
|
+
form?: Record<string, any>;
|
|
47
|
+
onSuccess?: (e: CustomEvent<_descope_core_js_sdk.JWTResponse>) => void;
|
|
48
|
+
onError?: (
|
|
49
|
+
e: CustomEvent<{
|
|
50
|
+
errorCode: string;
|
|
51
|
+
errorDescription: string;
|
|
52
|
+
errorMessage?: string;
|
|
53
|
+
retryAfter?: string;
|
|
54
|
+
}>
|
|
55
|
+
) => void;
|
|
56
|
+
onReady?: (e: CustomEvent<{}>) => void;
|
|
57
|
+
logger?: Partial<any>;
|
|
58
|
+
tenant?: string;
|
|
59
|
+
theme?: _2.ThemeOptions;
|
|
60
|
+
locale?: string;
|
|
61
|
+
autoFocus?: _2.AutoFocusOptions;
|
|
62
|
+
validateOnBlur?: boolean;
|
|
63
|
+
restartOnError?: boolean;
|
|
64
|
+
debug?: boolean;
|
|
65
|
+
telemetryKey?: string;
|
|
66
|
+
redirectUrl?: string;
|
|
67
|
+
errorTransformer?: (error: { text: string; type: string }) => string;
|
|
68
|
+
client?: Record<string, any>;
|
|
69
|
+
styleId?: string;
|
|
70
|
+
} & AdditionalProps
|
|
71
|
+
>;
|
|
72
|
+
declare const SignUpFlow: _1.ComponentType<
|
|
73
|
+
{
|
|
74
|
+
form?: Record<string, any>;
|
|
75
|
+
onSuccess?: (e: CustomEvent<_descope_core_js_sdk.JWTResponse>) => void;
|
|
76
|
+
onError?: (
|
|
77
|
+
e: CustomEvent<{
|
|
78
|
+
errorCode: string;
|
|
79
|
+
errorDescription: string;
|
|
80
|
+
errorMessage?: string;
|
|
81
|
+
retryAfter?: string;
|
|
82
|
+
}>
|
|
83
|
+
) => void;
|
|
84
|
+
onReady?: (e: CustomEvent<{}>) => void;
|
|
85
|
+
logger?: Partial<any>;
|
|
86
|
+
tenant?: string;
|
|
87
|
+
theme?: _2.ThemeOptions;
|
|
88
|
+
locale?: string;
|
|
89
|
+
autoFocus?: _2.AutoFocusOptions;
|
|
90
|
+
validateOnBlur?: boolean;
|
|
91
|
+
restartOnError?: boolean;
|
|
92
|
+
debug?: boolean;
|
|
93
|
+
telemetryKey?: string;
|
|
94
|
+
redirectUrl?: string;
|
|
95
|
+
errorTransformer?: (error: { text: string; type: string }) => string;
|
|
96
|
+
client?: Record<string, any>;
|
|
97
|
+
styleId?: string;
|
|
98
|
+
} & AdditionalProps
|
|
99
|
+
>;
|
|
100
|
+
declare const SignUpOrInFlow: _1.ComponentType<
|
|
101
|
+
{
|
|
102
|
+
form?: Record<string, any>;
|
|
103
|
+
onSuccess?: (e: CustomEvent<_descope_core_js_sdk.JWTResponse>) => void;
|
|
104
|
+
onError?: (
|
|
105
|
+
e: CustomEvent<{
|
|
106
|
+
errorCode: string;
|
|
107
|
+
errorDescription: string;
|
|
108
|
+
errorMessage?: string;
|
|
109
|
+
retryAfter?: string;
|
|
110
|
+
}>
|
|
111
|
+
) => void;
|
|
112
|
+
onReady?: (e: CustomEvent<{}>) => void;
|
|
113
|
+
logger?: Partial<any>;
|
|
114
|
+
tenant?: string;
|
|
115
|
+
theme?: _2.ThemeOptions;
|
|
116
|
+
locale?: string;
|
|
117
|
+
autoFocus?: _2.AutoFocusOptions;
|
|
118
|
+
validateOnBlur?: boolean;
|
|
119
|
+
restartOnError?: boolean;
|
|
120
|
+
debug?: boolean;
|
|
121
|
+
telemetryKey?: string;
|
|
122
|
+
redirectUrl?: string;
|
|
123
|
+
errorTransformer?: (error: { text: string; type: string }) => string;
|
|
124
|
+
client?: Record<string, any>;
|
|
125
|
+
styleId?: string;
|
|
126
|
+
} & AdditionalProps
|
|
127
|
+
>;
|
|
128
|
+
|
|
129
|
+
declare const UserManagement: _1.ComponentType<
|
|
130
|
+
{
|
|
131
|
+
logger?: Partial<any>;
|
|
132
|
+
tenant: string;
|
|
133
|
+
widgetId: string;
|
|
134
|
+
theme?: _descope_web_component.ThemeOptions;
|
|
135
|
+
debug?: boolean;
|
|
136
|
+
styleId?: string;
|
|
137
|
+
} & _1.RefAttributes<HTMLElement>
|
|
138
|
+
>;
|
|
139
|
+
declare const RoleManagement: _1.ComponentType<
|
|
140
|
+
{
|
|
141
|
+
logger?: Partial<any>;
|
|
142
|
+
tenant: string;
|
|
143
|
+
widgetId: string;
|
|
144
|
+
theme?: _descope_web_component.ThemeOptions;
|
|
145
|
+
debug?: boolean;
|
|
146
|
+
styleId?: string;
|
|
147
|
+
} & _1.RefAttributes<HTMLElement>
|
|
148
|
+
>;
|
|
149
|
+
declare const AccessKeyManagement: _1.ComponentType<
|
|
150
|
+
{
|
|
151
|
+
logger?: Partial<any>;
|
|
152
|
+
tenant: string;
|
|
153
|
+
widgetId: string;
|
|
154
|
+
theme?: _descope_web_component.ThemeOptions;
|
|
155
|
+
debug?: boolean;
|
|
156
|
+
styleId?: string;
|
|
157
|
+
} & _1.RefAttributes<HTMLElement>
|
|
158
|
+
>;
|
|
159
|
+
declare const AuditManagement: _1.ComponentType<
|
|
160
|
+
{
|
|
161
|
+
logger?: Partial<any>;
|
|
162
|
+
tenant: string;
|
|
163
|
+
widgetId: string;
|
|
164
|
+
theme?: _descope_web_component.ThemeOptions;
|
|
165
|
+
debug?: boolean;
|
|
166
|
+
styleId?: string;
|
|
167
|
+
} & _1.RefAttributes<HTMLElement>
|
|
168
|
+
>;
|
|
169
|
+
declare const UserProfile: _1.ComponentType<
|
|
170
|
+
Omit<
|
|
171
|
+
{
|
|
172
|
+
logger?: Partial<any>;
|
|
173
|
+
tenant: string;
|
|
174
|
+
widgetId: string;
|
|
175
|
+
theme?: _descope_web_component.ThemeOptions;
|
|
176
|
+
debug?: boolean;
|
|
177
|
+
styleId?: string;
|
|
178
|
+
},
|
|
179
|
+
'tenant'
|
|
180
|
+
> & {
|
|
181
|
+
onLogout?: (e: CustomEvent<any>) => void;
|
|
182
|
+
} & _1.RefAttributes<HTMLElement>
|
|
183
|
+
>;
|
|
184
|
+
declare const ApplicationsPortal: _1.ComponentType<
|
|
185
|
+
Omit<
|
|
186
|
+
{
|
|
187
|
+
logger?: Partial<any>;
|
|
188
|
+
tenant: string;
|
|
189
|
+
widgetId: string;
|
|
190
|
+
theme?: _descope_web_component.ThemeOptions;
|
|
191
|
+
debug?: boolean;
|
|
192
|
+
styleId?: string;
|
|
193
|
+
},
|
|
194
|
+
'tenant'
|
|
195
|
+
> & {
|
|
196
|
+
onLogout?: (e: CustomEvent<any>) => void;
|
|
197
|
+
} & _1.RefAttributes<HTMLElement>
|
|
198
|
+
>;
|
|
199
|
+
|
|
200
|
+
export {
|
|
201
|
+
AccessKeyManagement,
|
|
202
|
+
ApplicationsPortal,
|
|
203
|
+
AuditManagement,
|
|
204
|
+
AuthProvider,
|
|
205
|
+
Descope,
|
|
206
|
+
RoleManagement,
|
|
207
|
+
SignInFlow,
|
|
208
|
+
SignUpFlow,
|
|
209
|
+
SignUpOrInFlow,
|
|
210
|
+
UserManagement,
|
|
211
|
+
UserProfile
|
|
212
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { default as AuthProvider } from './shared/AuthProvider.js';
|
|
2
|
+
export {
|
|
3
|
+
Descope,
|
|
4
|
+
SignInFlow,
|
|
5
|
+
SignUpFlow,
|
|
6
|
+
SignUpOrInFlow
|
|
7
|
+
} from './shared/DescopeFlows.js';
|
|
8
|
+
export {
|
|
9
|
+
AccessKeyManagement,
|
|
10
|
+
ApplicationsPortal,
|
|
11
|
+
AuditManagement,
|
|
12
|
+
RoleManagement,
|
|
13
|
+
UserManagement,
|
|
14
|
+
UserProfile
|
|
15
|
+
} from './shared/DescopeWidgets.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server.js';
|
|
2
|
+
import descopeSdk from '@descope/node-sdk';
|
|
3
|
+
import { DEFAULT_PUBLIC_ROUTES, DESCOPE_SESSION_HEADER } from './constants.js';
|
|
4
|
+
import { getGlobalSdk } from './sdk.js';
|
|
5
|
+
import { mergeSearchParams } from './utils.js';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable no-console */
|
|
8
|
+
const getSessionJwt = (req) => {
|
|
9
|
+
let jwt = req.headers?.get('Authorization')?.split(' ')[1];
|
|
10
|
+
if (jwt) {
|
|
11
|
+
return jwt;
|
|
12
|
+
}
|
|
13
|
+
jwt = req.cookies?.get(descopeSdk.SessionTokenCookieName)?.value;
|
|
14
|
+
if (jwt) {
|
|
15
|
+
return jwt;
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
};
|
|
19
|
+
const isPublicRoute = (req, options) => {
|
|
20
|
+
// Ensure publicRoutes and privateRoutes are arrays, defaulting to empty arrays if not defined
|
|
21
|
+
const publicRoutes = options.publicRoutes || [];
|
|
22
|
+
const privateRoutes = options.privateRoutes || [];
|
|
23
|
+
const isDefaultPublicRoute = Object.values(DEFAULT_PUBLIC_ROUTES).includes(
|
|
24
|
+
req.nextUrl.pathname
|
|
25
|
+
);
|
|
26
|
+
if (publicRoutes.length > 0) {
|
|
27
|
+
if (privateRoutes.length > 0) {
|
|
28
|
+
console.warn(
|
|
29
|
+
'Both publicRoutes and privateRoutes are defined. Ignoring privateRoutes.'
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return isDefaultPublicRoute || publicRoutes.includes(req.nextUrl.pathname);
|
|
33
|
+
}
|
|
34
|
+
if (privateRoutes.length > 0) {
|
|
35
|
+
return (
|
|
36
|
+
isDefaultPublicRoute || !privateRoutes.includes(req.nextUrl.pathname)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
// If no routes are provided, all routes are private
|
|
40
|
+
return isDefaultPublicRoute;
|
|
41
|
+
};
|
|
42
|
+
const addSessionToHeadersIfExists = (headers, session) => {
|
|
43
|
+
if (session) {
|
|
44
|
+
const requestHeaders = new Headers(headers);
|
|
45
|
+
requestHeaders.set(
|
|
46
|
+
DESCOPE_SESSION_HEADER,
|
|
47
|
+
Buffer.from(JSON.stringify(session)).toString('base64')
|
|
48
|
+
);
|
|
49
|
+
return requestHeaders;
|
|
50
|
+
}
|
|
51
|
+
return headers;
|
|
52
|
+
};
|
|
53
|
+
// returns a Middleware that checks if the user is authenticated
|
|
54
|
+
// if the user is not authenticated, it redirects to the redirectUrl
|
|
55
|
+
// if the user is authenticated, it adds the session to the headers
|
|
56
|
+
const createAuthMiddleware =
|
|
57
|
+
(options = {}) =>
|
|
58
|
+
async (req) => {
|
|
59
|
+
console.debug('Auth middleware starts');
|
|
60
|
+
const jwt = getSessionJwt(req);
|
|
61
|
+
// check if the user is authenticated
|
|
62
|
+
let session;
|
|
63
|
+
try {
|
|
64
|
+
session = await getGlobalSdk({
|
|
65
|
+
projectId: options.projectId,
|
|
66
|
+
baseUrl: options.baseUrl
|
|
67
|
+
}).validateJwt(jwt);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.debug('Auth middleware, Failed to validate JWT', err);
|
|
70
|
+
if (!isPublicRoute(req, options)) {
|
|
71
|
+
const redirectUrl = options.redirectUrl || DEFAULT_PUBLIC_ROUTES.signIn;
|
|
72
|
+
const url = req.nextUrl.clone();
|
|
73
|
+
// Create a URL object for redirectUrl. 'http://example.com' is just a placeholder.
|
|
74
|
+
const parsedRedirectUrl = new URL(redirectUrl, 'http://example.com');
|
|
75
|
+
url.pathname = parsedRedirectUrl.pathname;
|
|
76
|
+
const searchParams = mergeSearchParams(
|
|
77
|
+
url.search,
|
|
78
|
+
parsedRedirectUrl.search
|
|
79
|
+
);
|
|
80
|
+
if (searchParams) {
|
|
81
|
+
url.search = searchParams;
|
|
82
|
+
}
|
|
83
|
+
console.debug(`Auth middleware, Redirecting to ${redirectUrl}`);
|
|
84
|
+
return NextResponse.redirect(url);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
console.debug('Auth middleware finishes');
|
|
88
|
+
// add the session to the request, if it exists
|
|
89
|
+
const headers = addSessionToHeadersIfExists(req.headers, session);
|
|
90
|
+
return NextResponse.next({
|
|
91
|
+
request: {
|
|
92
|
+
headers
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export { createAuthMiddleware as default };
|
|
98
|
+
//# sourceMappingURL=authMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authMiddleware.js","sources":["../../src/server/authMiddleware.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { NextRequest, NextResponse } from 'next/server';\nimport descopeSdk from '@descope/node-sdk';\nimport type { AuthenticationInfo } from '@descope/node-sdk';\nimport { DEFAULT_PUBLIC_ROUTES, DESCOPE_SESSION_HEADER } from './constants';\nimport { getGlobalSdk } from './sdk';\nimport { mergeSearchParams } from './utils';\n\ntype MiddlewareOptions = {\n\t// The Descope project ID to use for authentication\n\t// Defaults to process.env.DESCOPE_PROJECT_ID\n\tprojectId?: string;\n\n\t// The base URL to use for authentication\n\t// Defaults to process.env.DESCOPE_BASE_URL\n\tbaseUrl?: string;\n\n\t// The URL to redirect to if the user is not authenticated\n\t// Defaults to process.env.SIGN_IN_ROUTE or '/sign-in' if not provided\n\t// NOTE: In case it contains query parameters that exist in the original URL, they will override the original query parameters. e.g. if the original URL is /page?param1=1¶m2=2 and the redirect URL is /sign-in?param1=3, the final redirect URL will be /sign-in?param1=3¶m2=2\n\tredirectUrl?: string;\n\n\t// An array of public routes that do not require authentication\n\t// In addition to the default public routes:\n\t// - process.env.SIGN_IN_ROUTE or /sign-in if not provided\n\t// - process.env.SIGN_UP_ROUTE or /sign-up if not provided\n\tpublicRoutes?: string[];\n\n\t// An array of private routes that require authentication\n\t// If privateRoutes is defined, routes not listed in this array will default to public routes\n\tprivateRoutes?: string[];\n};\n\nconst getSessionJwt = (req: NextRequest): string | undefined => {\n\tlet jwt = req.headers?.get('Authorization')?.split(' ')[1];\n\tif (jwt) {\n\t\treturn jwt;\n\t}\n\n\tjwt = req.cookies?.get(descopeSdk.SessionTokenCookieName)?.value;\n\tif (jwt) {\n\t\treturn jwt;\n\t}\n\treturn undefined;\n};\n\nconst isPublicRoute = (req: NextRequest, options: MiddlewareOptions) => {\n\t// Ensure publicRoutes and privateRoutes are arrays, defaulting to empty arrays if not defined\n\tconst publicRoutes = options.publicRoutes || [];\n\tconst privateRoutes = options.privateRoutes || [];\n\n\tconst isDefaultPublicRoute = Object.values(DEFAULT_PUBLIC_ROUTES).includes(\n\t\treq.nextUrl.pathname\n\t);\n\n\tif (publicRoutes.length > 0) {\n\t\tif (privateRoutes.length > 0) {\n\t\t\tconsole.warn(\n\t\t\t\t'Both publicRoutes and privateRoutes are defined. Ignoring privateRoutes.'\n\t\t\t);\n\t\t}\n\t\treturn isDefaultPublicRoute || publicRoutes.includes(req.nextUrl.pathname);\n\t}\n\n\tif (privateRoutes.length > 0) {\n\t\treturn (\n\t\t\tisDefaultPublicRoute || !privateRoutes.includes(req.nextUrl.pathname)\n\t\t);\n\t}\n\n\t// If no routes are provided, all routes are private\n\treturn isDefaultPublicRoute;\n};\n\nconst addSessionToHeadersIfExists = (\n\theaders: Headers,\n\tsession: AuthenticationInfo | undefined\n): Headers => {\n\tif (session) {\n\t\tconst requestHeaders = new Headers(headers);\n\t\trequestHeaders.set(\n\t\t\tDESCOPE_SESSION_HEADER,\n\t\t\tBuffer.from(JSON.stringify(session)).toString('base64')\n\t\t);\n\t\treturn requestHeaders;\n\t}\n\treturn headers;\n};\n\n// returns a Middleware that checks if the user is authenticated\n// if the user is not authenticated, it redirects to the redirectUrl\n// if the user is authenticated, it adds the session to the headers\nconst createAuthMiddleware =\n\t(options: MiddlewareOptions = {}) =>\n\tasync (req: NextRequest) => {\n\t\tconsole.debug('Auth middleware starts');\n\n\t\tconst jwt = getSessionJwt(req);\n\n\t\t// check if the user is authenticated\n\t\tlet session: AuthenticationInfo | undefined;\n\t\ttry {\n\t\t\tsession = await getGlobalSdk({\n\t\t\t\tprojectId: options.projectId,\n\t\t\t\tbaseUrl: options.baseUrl\n\t\t\t}).validateJwt(jwt);\n\t\t} catch (err) {\n\t\t\tconsole.debug('Auth middleware, Failed to validate JWT', err);\n\t\t\tif (!isPublicRoute(req, options)) {\n\t\t\t\tconst redirectUrl = options.redirectUrl || DEFAULT_PUBLIC_ROUTES.signIn;\n\t\t\t\tconst url = req.nextUrl.clone();\n\t\t\t\t// Create a URL object for redirectUrl. 'http://example.com' is just a placeholder.\n\t\t\t\tconst parsedRedirectUrl = new URL(redirectUrl, 'http://example.com');\n\t\t\t\turl.pathname = parsedRedirectUrl.pathname;\n\n\t\t\t\tconst searchParams = mergeSearchParams(\n\t\t\t\t\turl.search,\n\t\t\t\t\tparsedRedirectUrl.search\n\t\t\t\t);\n\t\t\t\tif (searchParams) {\n\t\t\t\t\turl.search = searchParams;\n\t\t\t\t}\n\t\t\t\tconsole.debug(`Auth middleware, Redirecting to ${redirectUrl}`);\n\t\t\t\treturn NextResponse.redirect(url);\n\t\t\t}\n\t\t}\n\n\t\tconsole.debug('Auth middleware finishes');\n\t\t// add the session to the request, if it exists\n\t\tconst headers = addSessionToHeadersIfExists(req.headers, session);\n\t\treturn NextResponse.next({\n\t\t\trequest: {\n\t\t\t\theaders\n\t\t\t}\n\t\t});\n\t};\n\nexport default createAuthMiddleware;\n"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const DESCOPE_SESSION_HEADER = 'x-descope-session';
|
|
2
|
+
const baseHeaders = {
|
|
3
|
+
'x-descope-sdk-name': 'nextjs',
|
|
4
|
+
'x-descope-sdk-version': '0.3.36'
|
|
5
|
+
};
|
|
6
|
+
const DEFAULT_PUBLIC_ROUTES = {
|
|
7
|
+
signIn: process.env.SIGN_IN_ROUTE || '/sign-in',
|
|
8
|
+
signUp: process.env.SIGN_UP_ROUTE || '/sign-up'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { DEFAULT_PUBLIC_ROUTES, DESCOPE_SESSION_HEADER, baseHeaders };
|
|
12
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../src/server/constants.ts"],"sourcesContent":["// Replaced in build time\ndeclare const BUILD_VERSION: string;\n\nexport const DESCOPE_SESSION_HEADER = 'x-descope-session';\n\nexport const baseHeaders = {\n\t'x-descope-sdk-name': 'nextjs',\n\t'x-descope-sdk-version': BUILD_VERSION\n};\n\nexport const DEFAULT_PUBLIC_ROUTES = {\n\tsignIn: process.env.SIGN_IN_ROUTE || '/sign-in',\n\tsignUp: process.env.SIGN_UP_ROUTE || '/sign-up'\n};\n"],"names":[],"mappings":"AAGO,MAAM,sBAAsB,GAAG;AAEzB,MAAA,WAAW,GAAG;AAC1B,IAAA,oBAAoB,EAAE,QAAQ;AAC9B,IAAA,uBAAuB,EAAE;;AAGb,MAAA,qBAAqB,GAAG;AACpC,IAAA,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,UAAU;AAC/C,IAAA,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './shared';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
type MiddlewareOptions = {
|
|
3
|
+
projectId?: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
redirectUrl?: string;
|
|
6
|
+
publicRoutes?: string[];
|
|
7
|
+
privateRoutes?: string[];
|
|
8
|
+
};
|
|
9
|
+
declare const createAuthMiddleware: (
|
|
10
|
+
options?: MiddlewareOptions
|
|
11
|
+
) => (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
12
|
+
export default createAuthMiddleware;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const DESCOPE_SESSION_HEADER = 'x-descope-session';
|
|
2
|
+
export declare const baseHeaders: {
|
|
3
|
+
'x-descope-sdk-name': string;
|
|
4
|
+
'x-descope-sdk-version': string;
|
|
5
|
+
};
|
|
6
|
+
export declare const DEFAULT_PUBLIC_ROUTES: {
|
|
7
|
+
signIn: string;
|
|
8
|
+
signUp: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import descopeSdk from '@descope/node-sdk';
|
|
2
|
+
type Sdk = ReturnType<typeof descopeSdk>;
|
|
3
|
+
type CreateSdkParams = Omit<Parameters<typeof descopeSdk>[0], 'projectId'> & {
|
|
4
|
+
projectId?: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
export declare const createSdk: (config?: CreateSdkParams) => Sdk;
|
|
7
|
+
export declare const getGlobalSdk: (
|
|
8
|
+
config?: Pick<CreateSdkParams, 'projectId' | 'baseUrl'>
|
|
9
|
+
) => Sdk;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mergeSearchParams: (...searchParams: string[]) => string;
|