@descope/nextjs-sdk 0.3.37 → 0.4.0

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.
Files changed (104) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/client/index.js +48 -0
  3. package/dist/cjs/client/index.js.map +1 -0
  4. package/dist/cjs/index.js +20 -0
  5. package/dist/cjs/index.js.map +1 -0
  6. package/dist/cjs/server/authMiddleware.js +87 -0
  7. package/dist/cjs/server/authMiddleware.js.map +1 -0
  8. package/dist/cjs/server/constants.js +16 -0
  9. package/dist/cjs/server/constants.js.map +1 -0
  10. package/dist/cjs/server/index.js +13 -0
  11. package/dist/cjs/server/index.js.map +1 -0
  12. package/dist/cjs/server/sdk.js +29 -0
  13. package/dist/cjs/server/sdk.js.map +1 -0
  14. package/dist/cjs/server/session.js +31 -0
  15. package/dist/cjs/server/session.js.map +1 -0
  16. package/dist/cjs/server/utils.js +24 -0
  17. package/dist/cjs/server/utils.js.map +1 -0
  18. package/dist/cjs/shared/AuthProvider.js +15 -0
  19. package/dist/cjs/shared/AuthProvider.js.map +1 -0
  20. package/dist/cjs/shared/DescopeFlows.js +50 -0
  21. package/dist/cjs/shared/DescopeFlows.js.map +1 -0
  22. package/dist/cjs/shared/DescopeWidgets.js +27 -0
  23. package/dist/cjs/shared/DescopeWidgets.js.map +1 -0
  24. package/dist/cjs/shared/constants.js +10 -0
  25. package/dist/cjs/shared/constants.js.map +1 -0
  26. package/dist/esm/server/authMiddleware.js.map +1 -0
  27. package/dist/{server → esm/server}/constants.js +1 -1
  28. package/dist/esm/server/constants.js.map +1 -0
  29. package/dist/esm/server/sdk.js.map +1 -0
  30. package/dist/{server → esm/server}/session.js +2 -4
  31. package/dist/esm/server/session.js.map +1 -0
  32. package/dist/esm/server/utils.js.map +1 -0
  33. package/dist/esm/shared/AuthProvider.js.map +1 -0
  34. package/dist/esm/shared/DescopeFlows.js.map +1 -0
  35. package/dist/esm/shared/DescopeWidgets.js.map +1 -0
  36. package/dist/{shared → esm/shared}/constants.js +1 -1
  37. package/dist/esm/shared/constants.js.map +1 -0
  38. package/dist/{client/dts/src → types}/server/session.d.ts +1 -1
  39. package/dist/{client/dts/src → types}/shared/DescopeFlows.d.ts +8 -0
  40. package/package.json +28 -24
  41. package/dist/client/index.d.ts +0 -1
  42. package/dist/dts/src/client/index.d.ts +0 -1
  43. package/dist/dts/src/index.d.ts +0 -1
  44. package/dist/dts/src/server/authMiddleware.d.ts +0 -10
  45. package/dist/dts/src/server/constants.d.ts +0 -9
  46. package/dist/dts/src/server/index.d.ts +0 -3
  47. package/dist/dts/src/server/sdk.d.ts +0 -8
  48. package/dist/dts/src/server/session.d.ts +0 -4
  49. package/dist/dts/src/server/utils.d.ts +0 -1
  50. package/dist/dts/src/shared/AuthProvider.d.ts +0 -3
  51. package/dist/dts/src/shared/DescopeFlows.d.ts +0 -117
  52. package/dist/dts/src/shared/DescopeWidgets.d.ts +0 -54
  53. package/dist/dts/src/shared/constants.d.ts +0 -4
  54. package/dist/dts/src/shared/index.d.ts +0 -3
  55. package/dist/dts/src/types.d.ts +0 -1
  56. package/dist/index.d.ts +0 -177
  57. package/dist/server/authMiddleware.js.map +0 -1
  58. package/dist/server/constants.js.map +0 -1
  59. package/dist/server/dts/src/client/index.d.ts +0 -1
  60. package/dist/server/dts/src/index.d.ts +0 -1
  61. package/dist/server/dts/src/server/authMiddleware.d.ts +0 -10
  62. package/dist/server/dts/src/server/constants.d.ts +0 -9
  63. package/dist/server/dts/src/server/index.d.ts +0 -3
  64. package/dist/server/dts/src/server/sdk.d.ts +0 -8
  65. package/dist/server/dts/src/server/session.d.ts +0 -4
  66. package/dist/server/dts/src/server/utils.d.ts +0 -1
  67. package/dist/server/dts/src/shared/AuthProvider.d.ts +0 -3
  68. package/dist/server/dts/src/shared/DescopeFlows.d.ts +0 -117
  69. package/dist/server/dts/src/shared/DescopeWidgets.d.ts +0 -54
  70. package/dist/server/dts/src/shared/constants.d.ts +0 -4
  71. package/dist/server/dts/src/shared/index.d.ts +0 -3
  72. package/dist/server/dts/src/types.d.ts +0 -1
  73. package/dist/server/index.d.ts +0 -23
  74. package/dist/server/sdk.js.map +0 -1
  75. package/dist/server/session.js.map +0 -1
  76. package/dist/server/utils.js.map +0 -1
  77. package/dist/shared/AuthProvider.js.map +0 -1
  78. package/dist/shared/DescopeFlows.js.map +0 -1
  79. package/dist/shared/DescopeWidgets.js.map +0 -1
  80. package/dist/shared/constants.js.map +0 -1
  81. /package/dist/{client → esm/client}/index.js +0 -0
  82. /package/dist/{client → esm/client}/index.js.map +0 -0
  83. /package/dist/{index.js → esm/index.js} +0 -0
  84. /package/dist/{index.js.map → esm/index.js.map} +0 -0
  85. /package/dist/{server → esm/server}/authMiddleware.js +0 -0
  86. /package/dist/{server → esm/server}/index.js +0 -0
  87. /package/dist/{server → esm/server}/index.js.map +0 -0
  88. /package/dist/{server → esm/server}/sdk.js +0 -0
  89. /package/dist/{server → esm/server}/utils.js +0 -0
  90. /package/dist/{shared → esm/shared}/AuthProvider.js +0 -0
  91. /package/dist/{shared → esm/shared}/DescopeFlows.js +0 -0
  92. /package/dist/{shared → esm/shared}/DescopeWidgets.js +0 -0
  93. /package/dist/{client/dts/src → types}/client/index.d.ts +0 -0
  94. /package/dist/{client/dts/src → types}/index.d.ts +0 -0
  95. /package/dist/{client/dts/src → types}/server/authMiddleware.d.ts +0 -0
  96. /package/dist/{client/dts/src → types}/server/constants.d.ts +0 -0
  97. /package/dist/{client/dts/src → types}/server/index.d.ts +0 -0
  98. /package/dist/{client/dts/src → types}/server/sdk.d.ts +0 -0
  99. /package/dist/{client/dts/src → types}/server/utils.d.ts +0 -0
  100. /package/dist/{client/dts/src → types}/shared/AuthProvider.d.ts +0 -0
  101. /package/dist/{client/dts/src → types}/shared/DescopeWidgets.d.ts +0 -0
  102. /package/dist/{client/dts/src → types}/shared/constants.d.ts +0 -0
  103. /package/dist/{client/dts/src → types}/shared/index.d.ts +0 -0
  104. /package/dist/{client/dts/src → types}/types.d.ts +0 -0
package/README.md CHANGED
@@ -207,7 +207,7 @@ Server Component:
207
207
  import { session } from '@descope/nextjs-sdk/server';
208
208
 
209
209
  async function Page() {
210
- const sessionRes = session();
210
+ const sessionRes = await session();
211
211
  if (!sessionRes) {
212
212
  // ...
213
213
  }
@@ -221,7 +221,7 @@ Route handler:
221
221
  ```js
222
222
  // src/pages/api/routes.ts
223
223
  export async function GET() {
224
- const currSession = session();
224
+ const currSession = await session();
225
225
  if (!currSession.isAuthenticated) {
226
226
  // ...
227
227
  }
@@ -0,0 +1,48 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var reactSdk = require('@descope/react-sdk');
5
+
6
+
7
+
8
+ Object.defineProperty(exports, "getJwtPermissions", {
9
+ enumerable: true,
10
+ get: function () { return reactSdk.getJwtPermissions; }
11
+ });
12
+ Object.defineProperty(exports, "getJwtRoles", {
13
+ enumerable: true,
14
+ get: function () { return reactSdk.getJwtRoles; }
15
+ });
16
+ Object.defineProperty(exports, "getRefreshToken", {
17
+ enumerable: true,
18
+ get: function () { return reactSdk.getRefreshToken; }
19
+ });
20
+ Object.defineProperty(exports, "getSessionToken", {
21
+ enumerable: true,
22
+ get: function () { return reactSdk.getSessionToken; }
23
+ });
24
+ Object.defineProperty(exports, "isRefreshTokenExpired", {
25
+ enumerable: true,
26
+ get: function () { return reactSdk.isRefreshTokenExpired; }
27
+ });
28
+ Object.defineProperty(exports, "isSessionTokenExpired", {
29
+ enumerable: true,
30
+ get: function () { return reactSdk.isSessionTokenExpired; }
31
+ });
32
+ Object.defineProperty(exports, "refresh", {
33
+ enumerable: true,
34
+ get: function () { return reactSdk.refresh; }
35
+ });
36
+ Object.defineProperty(exports, "useDescope", {
37
+ enumerable: true,
38
+ get: function () { return reactSdk.useDescope; }
39
+ });
40
+ Object.defineProperty(exports, "useSession", {
41
+ enumerable: true,
42
+ get: function () { return reactSdk.useSession; }
43
+ });
44
+ Object.defineProperty(exports, "useUser", {
45
+ enumerable: true,
46
+ get: function () { return reactSdk.useUser; }
47
+ });
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ var AuthProvider = require('./shared/AuthProvider.js');
4
+ var DescopeFlows = require('./shared/DescopeFlows.js');
5
+ var DescopeWidgets = require('./shared/DescopeWidgets.js');
6
+
7
+
8
+
9
+ exports.AuthProvider = AuthProvider;
10
+ exports.Descope = DescopeFlows.Descope;
11
+ exports.SignInFlow = DescopeFlows.SignInFlow;
12
+ exports.SignUpFlow = DescopeFlows.SignUpFlow;
13
+ exports.SignUpOrInFlow = DescopeFlows.SignUpOrInFlow;
14
+ exports.AccessKeyManagement = DescopeWidgets.AccessKeyManagement;
15
+ exports.ApplicationsPortal = DescopeWidgets.ApplicationsPortal;
16
+ exports.AuditManagement = DescopeWidgets.AuditManagement;
17
+ exports.RoleManagement = DescopeWidgets.RoleManagement;
18
+ exports.UserManagement = DescopeWidgets.UserManagement;
19
+ exports.UserProfile = DescopeWidgets.UserProfile;
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ var server_js = require('next/server.js');
4
+ var descopeSdk = require('@descope/node-sdk');
5
+ var constants = require('./constants.js');
6
+ var sdk = require('./sdk.js');
7
+ var utils = require('./utils.js');
8
+
9
+ /* eslint-disable no-console */
10
+ const getSessionJwt = (req) => {
11
+ let jwt = req.headers?.get('Authorization')?.split(' ')[1];
12
+ if (jwt) {
13
+ return jwt;
14
+ }
15
+ jwt = req.cookies?.get(descopeSdk.SessionTokenCookieName)?.value;
16
+ if (jwt) {
17
+ return jwt;
18
+ }
19
+ return undefined;
20
+ };
21
+ const isPublicRoute = (req, options) => {
22
+ // Ensure publicRoutes and privateRoutes are arrays, defaulting to empty arrays if not defined
23
+ const publicRoutes = options.publicRoutes || [];
24
+ const privateRoutes = options.privateRoutes || [];
25
+ const isDefaultPublicRoute = Object.values(constants.DEFAULT_PUBLIC_ROUTES).includes(req.nextUrl.pathname);
26
+ if (publicRoutes.length > 0) {
27
+ if (privateRoutes.length > 0) {
28
+ console.warn('Both publicRoutes and privateRoutes are defined. Ignoring privateRoutes.');
29
+ }
30
+ return isDefaultPublicRoute || publicRoutes.includes(req.nextUrl.pathname);
31
+ }
32
+ if (privateRoutes.length > 0) {
33
+ return (isDefaultPublicRoute || !privateRoutes.includes(req.nextUrl.pathname));
34
+ }
35
+ // If no routes are provided, all routes are private
36
+ return isDefaultPublicRoute;
37
+ };
38
+ const addSessionToHeadersIfExists = (headers, session) => {
39
+ if (session) {
40
+ const requestHeaders = new Headers(headers);
41
+ requestHeaders.set(constants.DESCOPE_SESSION_HEADER, Buffer.from(JSON.stringify(session)).toString('base64'));
42
+ return requestHeaders;
43
+ }
44
+ return headers;
45
+ };
46
+ // returns a Middleware that checks if the user is authenticated
47
+ // if the user is not authenticated, it redirects to the redirectUrl
48
+ // if the user is authenticated, it adds the session to the headers
49
+ const createAuthMiddleware = (options = {}) => async (req) => {
50
+ console.debug('Auth middleware starts');
51
+ const jwt = getSessionJwt(req);
52
+ // check if the user is authenticated
53
+ let session;
54
+ try {
55
+ session = await sdk.getGlobalSdk({
56
+ projectId: options.projectId,
57
+ baseUrl: options.baseUrl
58
+ }).validateJwt(jwt);
59
+ }
60
+ catch (err) {
61
+ console.debug('Auth middleware, Failed to validate JWT', err);
62
+ if (!isPublicRoute(req, options)) {
63
+ const redirectUrl = options.redirectUrl || constants.DEFAULT_PUBLIC_ROUTES.signIn;
64
+ const url = req.nextUrl.clone();
65
+ // Create a URL object for redirectUrl. 'http://example.com' is just a placeholder.
66
+ const parsedRedirectUrl = new URL(redirectUrl, 'http://example.com');
67
+ url.pathname = parsedRedirectUrl.pathname;
68
+ const searchParams = utils.mergeSearchParams(url.search, parsedRedirectUrl.search);
69
+ if (searchParams) {
70
+ url.search = searchParams;
71
+ }
72
+ console.debug(`Auth middleware, Redirecting to ${redirectUrl}`);
73
+ return server_js.NextResponse.redirect(url);
74
+ }
75
+ }
76
+ console.debug('Auth middleware finishes');
77
+ // add the session to the request, if it exists
78
+ const headers = addSessionToHeadersIfExists(req.headers, session);
79
+ return server_js.NextResponse.next({
80
+ request: {
81
+ headers
82
+ }
83
+ });
84
+ };
85
+
86
+ module.exports = createAuthMiddleware;
87
+ //# 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&param2=2 and the redirect URL is /sign-in?param1=3, the final redirect URL will be /sign-in?param1=3&param2=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":["DEFAULT_PUBLIC_ROUTES","DESCOPE_SESSION_HEADER","getGlobalSdk","mergeSearchParams","NextResponse"],"mappings":";;;;;;;;AAAA;AAiCA,MAAM,aAAa,GAAG,CAAC,GAAgB,KAAwB;AAC9D,IAAA,IAAI,GAAG,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,eAAe,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,CAAC,MAAM,EACV,iBAAiB,CAAC,MAAM,CACxB,CAAC;YACF,IAAI,YAAY,EAAE;AACjB,gBAAA,GAAG,CAAC,MAAM,GAAG,YAAY,CAAC;aAC1B;AACD,YAAA,OAAO,CAAC,KAAK,CAAC,mCAAmC,WAAW,CAAA,CAAE,CAAC,CAAC;AAChE,YAAA,OAAOC,sBAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SAClC;KACD;AAED,IAAA,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;;IAE1C,MAAM,OAAO,GAAG,2BAA2B,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClE,OAAOA,sBAAY,CAAC,IAAI,CAAC;AACxB,QAAA,OAAO,EAAE;YACR,OAAO;AACP,SAAA;AACD,KAAA,CAAC,CAAC;AACJ;;;;"}
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const DESCOPE_SESSION_HEADER = 'x-descope-session';
4
+ const baseHeaders = {
5
+ 'x-descope-sdk-name': 'nextjs',
6
+ 'x-descope-sdk-version': "0.4.0"
7
+ };
8
+ const DEFAULT_PUBLIC_ROUTES = {
9
+ signIn: process.env.SIGN_IN_ROUTE || '/sign-in',
10
+ signUp: process.env.SIGN_UP_ROUTE || '/sign-up'
11
+ };
12
+
13
+ exports.DEFAULT_PUBLIC_ROUTES = DEFAULT_PUBLIC_ROUTES;
14
+ exports.DESCOPE_SESSION_HEADER = DESCOPE_SESSION_HEADER;
15
+ exports.baseHeaders = baseHeaders;
16
+ //# 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,oBAAoB;AAE7C,MAAA,WAAW,GAAG;AAC1B,IAAA,oBAAoB,EAAE,QAAQ;AAC9B,IAAA,uBAAuB,EAAE,OAAa;EACrC;AAEW,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,UAAU;;;;;;;"}
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var authMiddleware = require('./authMiddleware.js');
4
+ var session = require('./session.js');
5
+ var sdk = require('./sdk.js');
6
+
7
+
8
+
9
+ exports.authMiddleware = authMiddleware;
10
+ exports.getSession = session.getSession;
11
+ exports.session = session.session;
12
+ exports.createSdk = sdk.createSdk;
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ var descopeSdk = require('@descope/node-sdk');
4
+ var constants = require('./constants.js');
5
+
6
+ let globalSdk;
7
+ const createSdk = (config) => descopeSdk({
8
+ ...config,
9
+ projectId: config?.projectId || process.env.DESCOPE_PROJECT_ID,
10
+ managementKey: config?.managementKey || process.env.DESCOPE_MANAGEMENT_KEY,
11
+ baseUrl: config?.baseUrl || process.env.DESCOPE_BASE_URL,
12
+ baseHeaders: {
13
+ ...config?.baseHeaders,
14
+ ...constants.baseHeaders
15
+ }
16
+ });
17
+ const getGlobalSdk = (config) => {
18
+ if (!globalSdk) {
19
+ if (!config?.projectId && !process.env.DESCOPE_PROJECT_ID) {
20
+ throw new Error('Descope project ID is required to create the SDK');
21
+ }
22
+ globalSdk = createSdk(config);
23
+ }
24
+ return globalSdk;
25
+ };
26
+
27
+ exports.createSdk = createSdk;
28
+ exports.getGlobalSdk = getGlobalSdk;
29
+ //# sourceMappingURL=sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.js","sources":["../../../src/server/sdk.ts"],"sourcesContent":["import descopeSdk from '@descope/node-sdk';\nimport { baseHeaders } from './constants';\n\ntype Sdk = ReturnType<typeof descopeSdk>;\ntype CreateSdkParams = Omit<Parameters<typeof descopeSdk>[0], 'projectId'> & {\n\tprojectId?: string | undefined;\n};\n\nlet globalSdk: Sdk;\n\nexport const createSdk = (config?: CreateSdkParams): Sdk =>\n\tdescopeSdk({\n\t\t...config,\n\t\tprojectId: config?.projectId || process.env.DESCOPE_PROJECT_ID,\n\t\tmanagementKey: config?.managementKey || process.env.DESCOPE_MANAGEMENT_KEY,\n\t\tbaseUrl: config?.baseUrl || process.env.DESCOPE_BASE_URL,\n\t\tbaseHeaders: {\n\t\t\t...config?.baseHeaders,\n\t\t\t...baseHeaders\n\t\t}\n\t});\n\nexport const getGlobalSdk = (\n\tconfig?: Pick<CreateSdkParams, 'projectId' | 'baseUrl'>\n): Sdk => {\n\tif (!globalSdk) {\n\t\tif (!config?.projectId && !process.env.DESCOPE_PROJECT_ID) {\n\t\t\tthrow new Error('Descope project ID is required to create the SDK');\n\t\t}\n\t\tglobalSdk = createSdk(config);\n\t}\n\n\treturn globalSdk;\n};\n"],"names":["baseHeaders"],"mappings":";;;;;AAQA,IAAI,SAAc,CAAC;AAEN,MAAA,SAAS,GAAG,CAAC,MAAwB,KACjD,UAAU,CAAC;AACV,IAAA,GAAG,MAAM;IACT,SAAS,EAAE,MAAM,EAAE,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB;IAC9D,aAAa,EAAE,MAAM,EAAE,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB;IAC1E,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB;AACxD,IAAA,WAAW,EAAE;QACZ,GAAG,MAAM,EAAE,WAAW;AACtB,QAAA,GAAGA,qBAAW;AACd,KAAA;AACD,CAAA,EAAE;AAES,MAAA,YAAY,GAAG,CAC3B,MAAuD,KAC/C;IACR,IAAI,CAAC,SAAS,EAAE;AACf,QAAA,IAAI,CAAC,MAAM,EAAE,SAAS,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE;AAC1D,YAAA,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;SACpE;AACD,QAAA,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;KAC9B;AAED,IAAA,OAAO,SAAS,CAAC;AAClB;;;;;"}
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ var headers_js = require('next/headers.js');
4
+ var constants = require('./constants.js');
5
+
6
+ const extractSession = (descopeSession) => {
7
+ if (!descopeSession) {
8
+ return undefined;
9
+ }
10
+ try {
11
+ const authInfo = JSON.parse(Buffer.from(descopeSession, 'base64').toString());
12
+ return authInfo;
13
+ }
14
+ catch (err) {
15
+ return undefined;
16
+ }
17
+ };
18
+ // returns the session token if it exists in the headers
19
+ // This function require middleware
20
+ const session = async () => {
21
+ const reqHeaders = await headers_js.headers();
22
+ const sessionHeader = reqHeaders.get(constants.DESCOPE_SESSION_HEADER);
23
+ return extractSession(sessionHeader);
24
+ };
25
+ // returns the session token if it exists in the request headers
26
+ // This function require middleware
27
+ const getSession = (req) => extractSession(req.headers[constants.DESCOPE_SESSION_HEADER.toLowerCase()]);
28
+
29
+ exports.getSession = getSession;
30
+ exports.session = session;
31
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sources":["../../../src/server/session.ts"],"sourcesContent":["import { AuthenticationInfo } from '@descope/node-sdk';\nimport { NextApiRequest } from 'next';\nimport { headers } from 'next/headers';\nimport { DESCOPE_SESSION_HEADER } from './constants';\n\nconst extractSession = (\n\tdescopeSession?: string\n): AuthenticationInfo | undefined => {\n\tif (!descopeSession) {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\tconst authInfo = JSON.parse(\n\t\t\tBuffer.from(descopeSession, 'base64').toString()\n\t\t) as AuthenticationInfo;\n\t\treturn authInfo;\n\t} catch (err) {\n\t\treturn undefined;\n\t}\n};\n// returns the session token if it exists in the headers\n// This function require middleware\nexport const session = async (): Promise<AuthenticationInfo | undefined> => {\n\tconst reqHeaders = await headers();\n\tconst sessionHeader = reqHeaders.get(DESCOPE_SESSION_HEADER);\n\treturn extractSession(sessionHeader);\n};\n\n// returns the session token if it exists in the request headers\n// This function require middleware\nexport const getSession = (\n\treq: NextApiRequest\n): AuthenticationInfo | undefined =>\n\textractSession(req.headers[DESCOPE_SESSION_HEADER.toLowerCase()] as string);\n"],"names":["headers","DESCOPE_SESSION_HEADER"],"mappings":";;;;;AAKA,MAAM,cAAc,GAAG,CACtB,cAAuB,KACY;IACnC,IAAI,CAAC,cAAc,EAAE;AACpB,QAAA,OAAO,SAAS,CAAC;KACjB;AACD,IAAA,IAAI;AACH,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAC1B,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAC1B,CAAC;AACxB,QAAA,OAAO,QAAQ,CAAC;KAChB;IAAC,OAAO,GAAG,EAAE;AACb,QAAA,OAAO,SAAS,CAAC;KACjB;AACF,CAAC,CAAC;AACF;AACA;AACa,MAAA,OAAO,GAAG,YAAoD;AAC1E,IAAA,MAAM,UAAU,GAAG,MAAMA,kBAAO,EAAE,CAAC;IACnC,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,CAACC,gCAAsB,CAAC,CAAC;AAC7D,IAAA,OAAO,cAAc,CAAC,aAAa,CAAC,CAAC;AACtC,EAAE;AAEF;AACA;MACa,UAAU,GAAG,CACzB,GAAmB,KAEnB,cAAc,CAAC,GAAG,CAAC,OAAO,CAACA,gCAAsB,CAAC,WAAW,EAAE,CAAW;;;;;"}
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ /* eslint-disable import/prefer-default-export */
4
+ /*
5
+ Merges multiple search params into one.
6
+ It will override according to the order of the search params
7
+ Examples:
8
+ - mergeSearchParams('?a=1', '?b=2') => 'a=1&b=2'
9
+ - mergeSearchParams('?a=1', '?a=2') => 'a=2'
10
+ - mergeSearchParams('?a=1', '?a=2', '?b=3') => 'a=2&b=3'
11
+ */
12
+ const mergeSearchParams = (...searchParams) => {
13
+ const res = searchParams.reduce((acc, curr) => {
14
+ const currParams = new URLSearchParams(curr);
15
+ currParams.forEach((value, key) => {
16
+ acc.set(key, value);
17
+ });
18
+ return acc;
19
+ }, new URLSearchParams());
20
+ return res.toString();
21
+ };
22
+
23
+ exports.mergeSearchParams = mergeSearchParams;
24
+ //# 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,15 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var reactSdk = require('@descope/react-sdk');
5
+ var React = require('react');
6
+ var constants = require('./constants.js');
7
+
8
+ // Override baseHeaders
9
+ Object.assign(reactSdk.baseHeaders, constants.baseHeaders);
10
+ const AuthProvider = ({ ...props }) => (
11
+ // by default we use sessionTokenViaCookie, so middleware will work out of the box
12
+ React.createElement(reactSdk.AuthProvider, { sessionTokenViaCookie: true, ...props }));
13
+
14
+ module.exports = AuthProvider;
15
+ //# 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,50 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var React = require('react');
5
+ var dynamic = require('next/dynamic.js');
6
+ var navigation_js = require('next/navigation.js');
7
+ var constants = require('./constants.js');
8
+
9
+ // Generalized function to dynamically import components from @descope/react-sdk
10
+ // Dynamic is needed because the Descope components has a side effect us
11
+ // and NextJS will load the page on the server even if it is a client side only page
12
+ const dynamicDescopeComponent = (componentName) => dynamic(async () => {
13
+ const DescopeComponents = await import('@descope/react-sdk');
14
+ // Override baseHeaders
15
+ Object.assign(DescopeComponents.baseHeaders, constants.baseHeaders);
16
+ const Component = DescopeComponents[componentName];
17
+ return ({ redirectAfterSuccess = '', redirectAfterError = '', ...props }) => {
18
+ const router = navigation_js.useRouter();
19
+ const modifiedProps = { ...props };
20
+ if (redirectAfterSuccess) {
21
+ modifiedProps.onSuccess = (...args) => {
22
+ if (props.onSuccess) {
23
+ props.onSuccess(...args);
24
+ }
25
+ router.push(redirectAfterSuccess);
26
+ };
27
+ }
28
+ if (redirectAfterError) {
29
+ modifiedProps.onError = (...args) => {
30
+ if (props.onError) {
31
+ props.onError(...args);
32
+ }
33
+ router.push(redirectAfterError);
34
+ };
35
+ }
36
+ return React.createElement(Component, { ...modifiedProps });
37
+ };
38
+ }, {
39
+ ssr: false
40
+ });
41
+ const Descope = dynamicDescopeComponent('Descope');
42
+ const SignInFlow = dynamicDescopeComponent('SignInFlow');
43
+ const SignUpFlow = dynamicDescopeComponent('SignUpFlow');
44
+ const SignUpOrInFlow = dynamicDescopeComponent('SignUpOrInFlow');
45
+
46
+ exports.Descope = Descope;
47
+ exports.SignInFlow = SignInFlow;
48
+ exports.SignUpFlow = SignUpFlow;
49
+ exports.SignUpOrInFlow = SignUpOrInFlow;
50
+ //# 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,27 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var dynamic = require('next/dynamic.js');
5
+ var reactSdk = require('@descope/react-sdk');
6
+
7
+ // a helper function to dynamically load the components
8
+ // This function prevents Next.js from trying to server-side render these components
9
+ // Update the helper function to use generics for preserving component prop types
10
+ const dynamicWidgetComponent = (Component) => dynamic(() => Promise.resolve(Component), {
11
+ ssr: false // Disable server-side rendering for this component
12
+ });
13
+ // Use the helper function to create dynamically loaded components
14
+ const UserManagement = dynamicWidgetComponent(reactSdk.UserManagement);
15
+ const RoleManagement = dynamicWidgetComponent(reactSdk.RoleManagement);
16
+ const AccessKeyManagement = dynamicWidgetComponent(reactSdk.AccessKeyManagement);
17
+ const AuditManagement = dynamicWidgetComponent(reactSdk.AuditManagement);
18
+ const UserProfile = dynamicWidgetComponent(reactSdk.UserProfile);
19
+ const ApplicationsPortal = dynamicWidgetComponent(reactSdk.ApplicationsPortal);
20
+
21
+ exports.AccessKeyManagement = AccessKeyManagement;
22
+ exports.ApplicationsPortal = ApplicationsPortal;
23
+ exports.AuditManagement = AuditManagement;
24
+ exports.RoleManagement = RoleManagement;
25
+ exports.UserManagement = UserManagement;
26
+ exports.UserProfile = UserProfile;
27
+ //# 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,10 @@
1
+ 'use strict';
2
+
3
+ // eslint-disable-next-line import/prefer-default-export
4
+ const baseHeaders = {
5
+ 'x-descope-sdk-name': 'nextjs',
6
+ 'x-descope-sdk-version': "0.4.0"
7
+ };
8
+
9
+ exports.baseHeaders = baseHeaders;
10
+ //# sourceMappingURL=constants.js.map
@@ -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,OAAa;;;;;"}
@@ -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&param2=2 and the redirect URL is /sign-in?param1=3, the final redirect URL will be /sign-in?param1=3&param2=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":";;;;;;AAAA;AAiCA,MAAM,aAAa,GAAG,CAAC,GAAg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BAAiB,CAAC,QAAQ,CAAC;AAE1C,YAAA,MAAM,YAAY,GAAG,iBAAiB,CACrC,GAAG,CAAC,MAAM,EACV,iBAAiB,CAAC,MAAM,CACxB,CAAC;YACF,IAAI,YAAY,EAAE;AACjB,gBAAA,GAAG,CAAC,MAAM,GAAG,YAAY,CAAC;aAC1B;AACD,YAAA,OAAO,CAAC,KAAK,CAAC,mCAAmC,WAAW,CAAA,CAAE,CAAC,CAAC;AAChE,YAAA,OAAO,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SAClC;KACD;AAED,IAAA,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;;IAE1C,MAAM,OAAO,GAAG,2BAA2B,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClE,OAAO,YAAY,CAAC,IAAI,CAAC;AACxB,QAAA,OAAO,EAAE;YACR,OAAO;AACP,SAAA;AACD,KAAA,CAAC,CAAC;AACJ;;;;"}
@@ -1,7 +1,7 @@
1
1
  const DESCOPE_SESSION_HEADER = 'x-descope-session';
2
2
  const baseHeaders = {
3
3
  'x-descope-sdk-name': 'nextjs',
4
- 'x-descope-sdk-version': "0.3.37"
4
+ 'x-descope-sdk-version': "0.4.0"
5
5
  };
6
6
  const DEFAULT_PUBLIC_ROUTES = {
7
7
  signIn: process.env.SIGN_IN_ROUTE || '/sign-in',
@@ -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,oBAAoB;AAE7C,MAAA,WAAW,GAAG;AAC1B,IAAA,oBAAoB,EAAE,QAAQ;AAC9B,IAAA,uBAAuB,EAAE,OAAa;EACrC;AAEW,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,UAAU;;;;;"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.js","sources":["../../../src/server/sdk.ts"],"sourcesContent":["import descopeSdk from '@descope/node-sdk';\nimport { baseHeaders } from './constants';\n\ntype Sdk = ReturnType<typeof descopeSdk>;\ntype CreateSdkParams = Omit<Parameters<typeof descopeSdk>[0], 'projectId'> & {\n\tprojectId?: string | undefined;\n};\n\nlet globalSdk: Sdk;\n\nexport const createSdk = (config?: CreateSdkParams): Sdk =>\n\tdescopeSdk({\n\t\t...config,\n\t\tprojectId: config?.projectId || process.env.DESCOPE_PROJECT_ID,\n\t\tmanagementKey: config?.managementKey || process.env.DESCOPE_MANAGEMENT_KEY,\n\t\tbaseUrl: config?.baseUrl || process.env.DESCOPE_BASE_URL,\n\t\tbaseHeaders: {\n\t\t\t...config?.baseHeaders,\n\t\t\t...baseHeaders\n\t\t}\n\t});\n\nexport const getGlobalSdk = (\n\tconfig?: Pick<CreateSdkParams, 'projectId' | 'baseUrl'>\n): Sdk => {\n\tif (!globalSdk) {\n\t\tif (!config?.projectId && !process.env.DESCOPE_PROJECT_ID) {\n\t\t\tthrow new Error('Descope project ID is required to create the SDK');\n\t\t}\n\t\tglobalSdk = createSdk(config);\n\t}\n\n\treturn globalSdk;\n};\n"],"names":[],"mappings":";;;AAQA,IAAI,SAAc,CAAC;AAEN,MAAA,SAAS,GAAG,CAAC,MAAwB,KACjD,UAAU,CAAC;AACV,IAAA,GAAG,MAAM;IACT,SAAS,EAAE,MAAM,EAAE,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB;IAC9D,aAAa,EAAE,MAAM,EAAE,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB;IAC1E,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB;AACxD,IAAA,WAAW,EAAE;QACZ,GAAG,MAAM,EAAE,WAAW;AACtB,QAAA,GAAG,WAAW;AACd,KAAA;AACD,CAAA,EAAE;AAES,MAAA,YAAY,GAAG,CAC3B,MAAuD,KAC/C;IACR,IAAI,CAAC,SAAS,EAAE;AACf,QAAA,IAAI,CAAC,MAAM,EAAE,SAAS,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE;AAC1D,YAAA,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;SACpE;AACD,QAAA,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;KAC9B;AAED,IAAA,OAAO,SAAS,CAAC;AAClB;;;;"}
@@ -15,10 +15,8 @@ const extractSession = (descopeSession) => {
15
15
  };
16
16
  // returns the session token if it exists in the headers
17
17
  // This function require middleware
18
- const session = () => {
19
- // from Next.js 15, headers() returns a Promise
20
- // It can still be used synchronously to facilitate migration
21
- const reqHeaders = headers();
18
+ const session = async () => {
19
+ const reqHeaders = await headers();
22
20
  const sessionHeader = reqHeaders.get(DESCOPE_SESSION_HEADER);
23
21
  return extractSession(sessionHeader);
24
22
  };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sources":["../../../src/server/session.ts"],"sourcesContent":["import { AuthenticationInfo } from '@descope/node-sdk';\nimport { NextApiRequest } from 'next';\nimport { headers } from 'next/headers';\nimport { DESCOPE_SESSION_HEADER } from './constants';\n\nconst extractSession = (\n\tdescopeSession?: string\n): AuthenticationInfo | undefined => {\n\tif (!descopeSession) {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\tconst authInfo = JSON.parse(\n\t\t\tBuffer.from(descopeSession, 'base64').toString()\n\t\t) as AuthenticationInfo;\n\t\treturn authInfo;\n\t} catch (err) {\n\t\treturn undefined;\n\t}\n};\n// returns the session token if it exists in the headers\n// This function require middleware\nexport const session = async (): Promise<AuthenticationInfo | undefined> => {\n\tconst reqHeaders = await headers();\n\tconst sessionHeader = reqHeaders.get(DESCOPE_SESSION_HEADER);\n\treturn extractSession(sessionHeader);\n};\n\n// returns the session token if it exists in the request headers\n// This function require middleware\nexport const getSession = (\n\treq: NextApiRequest\n): AuthenticationInfo | undefined =>\n\textractSession(req.headers[DESCOPE_SESSION_HEADER.toLowerCase()] as string);\n"],"names":[],"mappings":";;;AAKA,MAAM,cAAc,GAAG,CACtB,cAAuB,KACY;IACnC,IAAI,CAAC,cAAc,EAAE;AACpB,QAAA,OAAO,SAAS,CAAC;KACjB;AACD,IAAA,IAAI;AACH,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAC1B,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAC1B,CAAC;AACxB,QAAA,OAAO,QAAQ,CAAC;KAChB;IAAC,OAAO,GAAG,EAAE;AACb,QAAA,OAAO,SAAS,CAAC;KACjB;AACF,CAAC,CAAC;AACF;AACA;AACa,MAAA,OAAO,GAAG,YAAoD;AAC1E,IAAA,MAAM,UAAU,GAAG,MAAM,OAAO,EAAE,CAAC;IACnC,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAC7D,IAAA,OAAO,cAAc,CAAC,aAAa,CAAC,CAAC;AACtC,EAAE;AAEF;AACA;MACa,UAAU,GAAG,CACzB,GAAmB,KAEnB,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,sBAAsB,CAAC,WAAW,EAAE,CAAW;;;;"}
@@ -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 @@
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 @@
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 @@
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;;;;;;;;"}
@@ -1,7 +1,7 @@
1
1
  // eslint-disable-next-line import/prefer-default-export
2
2
  const baseHeaders = {
3
3
  'x-descope-sdk-name': 'nextjs',
4
- 'x-descope-sdk-version': "0.3.37"
4
+ 'x-descope-sdk-version': "0.4.0"
5
5
  };
6
6
 
7
7
  export { baseHeaders };
@@ -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,OAAa;;;;;"}
@@ -1,4 +1,4 @@
1
1
  import { AuthenticationInfo } from '@descope/node-sdk';
2
2
  import { NextApiRequest } from 'next';
3
- export declare const session: () => AuthenticationInfo | undefined;
3
+ export declare const session: () => Promise<AuthenticationInfo | undefined>;
4
4
  export declare const getSession: (req: NextApiRequest) => AuthenticationInfo | undefined;