@frontegg/nextjs 9.0.4 → 9.0.5-alpha.11469892684

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 (50) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +29 -8
  3. package/api/utils.js +24 -1
  4. package/api/utils.js.map +1 -1
  5. package/app/FronteggAppProvider.js +1 -1
  6. package/app/FronteggAppProvider.js.map +1 -1
  7. package/app/FronteggAppRouter.d.ts +7 -0
  8. package/app/FronteggAppRouter.js +25 -0
  9. package/app/FronteggAppRouter.js.map +1 -1
  10. package/app/getAppUrlForCustomLoginWithSubdomain.js +1 -1
  11. package/app/getAppUrlForCustomLoginWithSubdomain.js.map +1 -1
  12. package/app/helpers.d.ts +8 -2
  13. package/app/helpers.js +56 -11
  14. package/app/helpers.js.map +1 -1
  15. package/common/FronteggBaseProvider.js +4 -2
  16. package/common/FronteggBaseProvider.js.map +1 -1
  17. package/common/hooks.js +5 -2
  18. package/common/hooks.js.map +1 -1
  19. package/config/constants.d.ts +21 -0
  20. package/config/constants.js +4 -0
  21. package/config/constants.js.map +1 -1
  22. package/config/index.d.ts +3 -0
  23. package/config/index.js +37 -5
  24. package/config/index.js.map +1 -1
  25. package/edge/getSessionOnEdge.js +22 -5
  26. package/edge/getSessionOnEdge.js.map +1 -1
  27. package/index.js +1 -1
  28. package/middleware/ProxyRequestCallback.js +13 -13
  29. package/middleware/ProxyRequestCallback.js.map +1 -1
  30. package/no-ssr/FronteggProviderNoSSR.js +1 -1
  31. package/no-ssr/FronteggProviderNoSSR.js.map +1 -1
  32. package/package.json +1 -1
  33. package/pages/withFronteggApp/withFronteggApp.js +3 -1
  34. package/pages/withFronteggApp/withFronteggApp.js.map +1 -1
  35. package/sdkVersion.js +1 -1
  36. package/sdkVersion.js.map +1 -1
  37. package/types/index.d.ts +1 -0
  38. package/types/index.js.map +1 -1
  39. package/utils/cookies/helpers.js +7 -1
  40. package/utils/cookies/helpers.js.map +1 -1
  41. package/utils/cookies/index.js +32 -4
  42. package/utils/cookies/index.js.map +1 -1
  43. package/utils/fetchUserData/index.js +4 -0
  44. package/utils/fetchUserData/index.js.map +1 -1
  45. package/utils/initializeFronteggApp/index.js +2 -1
  46. package/utils/initializeFronteggApp/index.js.map +1 -1
  47. package/utils/refreshAccessTokenIfNeeded/helpers.js +6 -0
  48. package/utils/refreshAccessTokenIfNeeded/helpers.js.map +1 -1
  49. package/utils/refreshAccessTokenIfNeeded/index.js +5 -4
  50. package/utils/refreshAccessTokenIfNeeded/index.js.map +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## [9.0.5](https://github.com/frontegg/frontegg-nextjs/compare/v9.0.4...v9.0.5) (2024-10-22)
4
+
5
+ - FR-18356 - Fixed validations localization override type
6
+
7
+
8
+ ### NextJS Wrapper 9.0.5:
9
+ - Add Support for NextJS 15
10
+
3
11
  ## [9.0.4](https://github.com/frontegg/frontegg-nextjs/compare/v9.0.3...v9.0.4) (2024-10-22)
4
12
 
5
13
  - FR-18356 - Fixed validations localization override type
package/README.md CHANGED
@@ -29,7 +29,7 @@ and integrate them into their SaaS portals in up to 5 lines of code.
29
29
 
30
30
  To Add Frontegg to your existing Next.JS project, follow below steps:
31
31
 
32
- 1. Use package manager to install Frontegg Next.JS library.
32
+ Use package manager to install Frontegg Next.JS library.
33
33
 
34
34
  ```bash
35
35
  npm install --save @frontegg/nextjs
@@ -41,7 +41,10 @@ To Add Frontegg to your existing Next.JS project, follow below steps:
41
41
  yarn add --save @frontegg/nextjs
42
42
  ```
43
43
 
44
- 2. Wrap the default export with `withFronteggApp` in `./pages/_app.tsx`:
44
+
45
+ **If you're using the App Directory architecture, you can skip the following Pages architecture steps and refer to the [AppDir guide](#nextjs-appdir-architecture) instead.**
46
+
47
+ 1. Wrap the default export with `withFronteggApp` in `./pages/_app.tsx`:
45
48
 
46
49
  ```tsx
47
50
  // ./pages/_app.tsx
@@ -58,7 +61,7 @@ To Add Frontegg to your existing Next.JS project, follow below steps:
58
61
  });
59
62
  ```
60
63
 
61
- 3. Create files for frontegg middleware under `./pages/api/frontegg/[...frontegg-middleware].ts`:
64
+ 2. Create files for frontegg middleware under `./pages/api/frontegg/[...frontegg-middleware].ts`:
62
65
 
63
66
  ```tsx
64
67
  // ./pages/api/frontegg/[...frontegg-middleware].ts
@@ -66,7 +69,7 @@ To Add Frontegg to your existing Next.JS project, follow below steps:
66
69
  export { fronteggMiddleware as default } from '@frontegg/nextjs/middleware';
67
70
  ```
68
71
 
69
- 4. Create placeholder pages for frontegg router under `./pages/[...frontegg-router].tsx`:
72
+ 3. Create placeholder pages for frontegg router under `./pages/[...frontegg-router].tsx`:
70
73
 
71
74
  ```tsx
72
75
  // ./pages/[...frontegg-router].tsx
@@ -126,8 +129,14 @@ FRONTEGG_CLIENT_SECRET='{YOUR_APPLICATION_CLIENT_SECRET}'
126
129
  # node -e "console.log(crypto.randomBytes(32).toString('hex'))"
127
130
  FRONTEGG_ENCRYPTION_PASSWORD='{SESSION_ENCRYPTION_PASSWORD}'
128
131
 
129
- # The stateless session cookie name
130
- FRONTEGG_COOKIE_NAME='fe_session'
132
+ # The stateless cookie name for storing the encrypted JWT
133
+ # value as session cookies for supporting getServerSideProps and ServerComponents
134
+ FRONTEGG_COOKIE_NAME='FRONTEGG_COOKIE_NAME'
135
+
136
+ # Specifies the domain for storing the encrypted JWT as session cookies,
137
+ # enabling support for `getServerSideProps` and `ServerComponents`.
138
+ # If not provided, the domain will be the same as the `APP_URL` environment variable.
139
+ FRONTEGG_COOKIE_DOMAIN='FRONTEGG_COOKIE_DOMAIN'
131
140
 
132
141
  # The JWT public key generated by Frontegg to verify JWT before creating a session.
133
142
  # Retrieve it by visiting: https://[YOUR_FRONTEGG_DOMAIN]/.well-known/jwks.json.
@@ -238,7 +247,7 @@ export const getServerSideProps: GetServerSideProps = withSSRSession(
238
247
  );
239
248
  ```
240
249
 
241
- ## Next.js 13
250
+ ## Next.js (AppDir architecture)
242
251
  ### wrapping your application
243
252
  ```tsx
244
253
  // ./app/layout.tsx
@@ -256,9 +265,21 @@ export default function RootLayout({ children }: { children: React.ReactNode })
256
265
  }
257
266
  ```
258
267
 
259
- ### routing
268
+ ### Routing
269
+
270
+
260
271
  ```tsx
261
272
  // ./app/[...frontegg-router]/page.tsx
273
+
274
+ /**
275
+ * For Next.js 15+ use the following FronteggAppRouterAsync as default export
276
+ */
277
+ export { FronteggAppRouterAsync as default } from '@frontegg/nextjs/app';
278
+
279
+
280
+ /**
281
+ * For Next.js 14 and below use the following FronteggAppRouter as default export
282
+ */
262
283
  export { FronteggAppRouter as default } from '@frontegg/nextjs/app';
263
284
  ```
264
285
 
package/api/utils.js CHANGED
@@ -66,6 +66,7 @@ function removeInvalidHeaders(headers) {
66
66
  * These header is used to identify the tenant for login per tenant feature
67
67
  */
68
68
  const CUSTOM_LOGIN_HEADER = 'frontegg-login-alias';
69
+
69
70
  /**
70
71
  * Build fetch request headers, remove invalid http headers
71
72
  * @param headers - Incoming request headers
@@ -75,9 +76,24 @@ function buildRequestHeaders(headers) {
75
76
  let cookie = headers['cookie'];
76
77
  if (cookie != null && typeof cookie === 'string') {
77
78
  cookie = cookie.replace(/fe_session-[^=]*=[^;]*$/, '').replace(/fe_session-[^=]*=[^;]*;/, '');
79
+ if (_config.default.rewriteCookieByAppId && _config.default.appId) {
80
+ cookie = cookie.split(';').filter(cookieStr => !cookieStr.trim().startsWith(`fe_refresh_${_config.default.clientId.replace('-', '')}`)).join(';');
81
+ cookie = cookie.replace(`fe_refresh_${_config.default.appId.replace('-', '')}`, `fe_refresh_${_config.default.clientId.replace('-', '')}`);
82
+ }
78
83
  }
79
84
  if (cookie != null && typeof cookie === 'object') {
80
- cookie = Object.entries(cookie).map(([key, value]) => `${key}=${value}`).join('; ');
85
+ cookie = Object.entries(cookie).filter(([key]) => {
86
+ if (_config.default.rewriteCookieByAppId && _config.default.appId) {
87
+ return key !== `fe_refresh_${_config.default.clientId.replace('-', '')}`;
88
+ }
89
+ return true;
90
+ }).map(([key, value]) => {
91
+ if (_config.default.rewriteCookieByAppId && _config.default.appId && key === `fe_refresh_${_config.default.appId.replace('-', '')}`) {
92
+ return `fe_refresh_${_config.default.clientId.replace('-', '')}=${value}`;
93
+ } else {
94
+ return `${key}=${value}`;
95
+ }
96
+ }).join('; ');
81
97
  }
82
98
  const preparedHeaders = {
83
99
  authorization: headers['authorization'],
@@ -92,6 +108,13 @@ function buildRequestHeaders(headers) {
92
108
  'x-frontegg-framework': `next@${_package.default.version}`,
93
109
  'x-frontegg-sdk': `@frontegg/nextjs@${_sdkVersion.default.version}`
94
110
  };
111
+ if (headers['frontegg-requested-application-id']) {
112
+ preparedHeaders['frontegg-requested-application-id'] = headers['frontegg-requested-application-id'];
113
+ }
114
+ const clientIp = headers['cf-connecting-ip'] || headers['x-original-forwarded-for'] || headers['x-forwarded-for'];
115
+ if (clientIp) {
116
+ preparedHeaders['x-original-forwarded-for'] = clientIp;
117
+ }
95
118
  if (headers[CUSTOM_LOGIN_HEADER]) {
96
119
  preparedHeaders[CUSTOM_LOGIN_HEADER] = headers[CUSTOM_LOGIN_HEADER];
97
120
  }
package/api/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["_config","_interopRequireDefault","require","_sdkVersion","_package","_restApi","_constants","Get","url","credentials","headers","fetch","method","exports","Post","body","removeInvalidHeaders","newHeaders","_extends2","default","Object","keys","forEach","key","val","Array","isArray","headerCharRegex","exec","undefined","length","CUSTOM_LOGIN_HEADER","buildRequestHeaders","cookie","replace","entries","map","value","join","preparedHeaders","authorization","accept","origin","config","baseUrl","nextjsPkg","version","sdkVersion","parseHttpResponse","res","ok","json","isMiddlewarePath","path","isAuthPath","fronteggAuthApiRoutesRegex","find","pathRegex","RegExp","test","isSocialLoginPath","endsWith"],"sources":["../../../../packages/nextjs/src/api/utils.ts"],"sourcesContent":["import config from '../config';\nimport sdkVersion from '../sdkVersion';\nimport nextjsPkg from 'next/package.json';\nimport { fronteggAuthApiRoutesRegex } from '@frontegg/rest-api';\nimport { headerCharRegex } from '../utils/common/constants';\n\ninterface GetRequestOptions {\n url: string;\n credentials?: RequestCredentials;\n headers?: HeadersInit;\n}\n\nexport const Get = ({ url, credentials = 'include', headers }: GetRequestOptions) =>\n fetch(url, { method: 'GET', credentials, headers });\n\ninterface PostRequestOptions extends GetRequestOptions {\n body: string;\n}\n\nexport const Post = ({ url, credentials = 'include', headers, body }: PostRequestOptions) =>\n fetch(url, { method: 'POST', credentials, headers, body });\n\n/**\n * NodeJS 18 start using undici as http request handler,\n * undici http request does not accept invalid headers\n * for more details see:\n * https://github.com/nodejs/undici/blob/2b260c997ad4efe4ed2064b264b4b546a59e7a67/lib/core/request.js#L282\n * @param headers\n */\nexport function removeInvalidHeaders(headers: Record<string, string>) {\n const newHeaders = { ...headers };\n Object.keys(newHeaders).forEach((key: string) => {\n const val: any = headers[key];\n if (val && typeof val === 'object' && !Array.isArray(val)) {\n delete newHeaders[key];\n } else if (headerCharRegex.exec(val) !== null) {\n delete newHeaders[key];\n } else if (val === undefined || val === null) {\n delete newHeaders[key];\n } else if (key.length === 10 && key === 'connection') {\n delete newHeaders[key];\n }\n });\n return newHeaders;\n}\n\n/**\n * These header is used to identify the tenant for login per tenant feature\n */\nexport const CUSTOM_LOGIN_HEADER = 'frontegg-login-alias';\n/**\n * Build fetch request headers, remove invalid http headers\n * @param headers - Incoming request headers\n */\nexport function buildRequestHeaders(headers: Record<string, any>): Record<string, string> {\n let cookie = headers['cookie'];\n if (cookie != null && typeof cookie === 'string') {\n cookie = cookie.replace(/fe_session-[^=]*=[^;]*$/, '').replace(/fe_session-[^=]*=[^;]*;/, '');\n }\n if (cookie != null && typeof cookie === 'object') {\n cookie = Object.entries(cookie)\n .map(([key, value]) => `${key}=${value}`)\n .join('; ');\n }\n\n const preparedHeaders: Record<string, string> = {\n authorization: headers['authorization'],\n 'accept-encoding': headers['accept-encoding'],\n 'accept-language': headers['accept-language'],\n accept: headers['accept'],\n 'content-type': 'application/json',\n origin: config.baseUrl,\n cookie,\n 'user-agent': headers['user-agent'],\n 'cache-control': headers['cache-control'],\n 'x-frontegg-framework': `next@${nextjsPkg.version}`,\n 'x-frontegg-sdk': `@frontegg/nextjs@${sdkVersion.version}`,\n };\n\n if (headers[CUSTOM_LOGIN_HEADER]) {\n preparedHeaders[CUSTOM_LOGIN_HEADER] = headers[CUSTOM_LOGIN_HEADER];\n }\n return removeInvalidHeaders({ ...preparedHeaders });\n}\n\n/**\n * Return parsed json response if http status code = 200\n * @param res\n */\nexport const parseHttpResponse = async <T>(res: Response): Promise<T | undefined> => {\n if (!res.ok) {\n return undefined;\n }\n return await res.json();\n};\n\n/**\n * Checks if the given path should be forwarded to the Next.js server middleware.\n *\n *\n * @param {string} path - The path to check for authentication API routes.\n * @returns {boolean} Returns true if the path is a frontegg authentication API route or ends with '/postlogin' or '/prelogin'; otherwise, returns false.\n */\nexport function isMiddlewarePath(path: string): boolean {\n let isAuthPath =\n fronteggAuthApiRoutesRegex.find((pathRegex) => {\n if (typeof pathRegex === 'string') {\n return pathRegex === path;\n } else {\n return new RegExp(pathRegex).test(path);\n }\n }) != null;\n\n // if(!isAuthPath){\n // isAuthPath = /^\\/identity\\/resources\\/auth\\/v[0-9]*\\/user\\/sso\\/[^\\/]*\\/postlogin$/g.test(path)\n // }\n // if(!isAuthPath){\n // isAuthPath = /^\\/identity\\/resources\\/auth\\/v[0-9]*\\/passwordless\\/[^\\/]*\\/prelogin$/g.test(path)\n // }\n // if(!isAuthPath){\n // isAuthPath = /^\\/identity\\/resources\\/auth\\/v[0-9]*\\/[^\\/]*\\/prelogin$/g.test(path)\n // }\n\n if (!isAuthPath) {\n const isSocialLoginPath = /^\\/identity\\/resources\\/auth\\/v[0-9]*\\/user\\/sso\\/default\\/[^\\/]*\\/prelogin$/.test(path);\n isAuthPath = (path.endsWith('/postlogin') || path.endsWith('/prelogin')) && !isSocialLoginPath;\n }\n\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CAAC,IAAIR,IAAI,CAACQ,QAAQ,CAAC,WAAW,CAAC,KAAK,CAACD,iBAAiB;EAChG;EAEA,OAAON,UAAU;AACnB"}
1
+ {"version":3,"file":"utils.js","names":["_config","_interopRequireDefault","require","_sdkVersion","_package","_restApi","_constants","Get","url","credentials","headers","fetch","method","exports","Post","body","removeInvalidHeaders","newHeaders","_extends2","default","Object","keys","forEach","key","val","Array","isArray","headerCharRegex","exec","undefined","length","CUSTOM_LOGIN_HEADER","buildRequestHeaders","cookie","replace","config","rewriteCookieByAppId","appId","split","filter","cookieStr","trim","startsWith","clientId","join","entries","map","value","preparedHeaders","authorization","accept","origin","baseUrl","nextjsPkg","version","sdkVersion","clientIp","parseHttpResponse","res","ok","json","isMiddlewarePath","path","isAuthPath","fronteggAuthApiRoutesRegex","find","pathRegex","RegExp","test","isSocialLoginPath","endsWith"],"sources":["../../../../packages/nextjs/src/api/utils.ts"],"sourcesContent":["import config from '../config';\nimport sdkVersion from '../sdkVersion';\nimport nextjsPkg from 'next/package.json';\nimport { fronteggAuthApiRoutesRegex } from '@frontegg/rest-api';\nimport { headerCharRegex } from '../utils/common/constants';\n\ninterface GetRequestOptions {\n url: string;\n credentials?: RequestCredentials;\n headers?: HeadersInit;\n}\n\nexport const Get = ({ url, credentials = 'include', headers }: GetRequestOptions) =>\n fetch(url, { method: 'GET', credentials, headers });\n\ninterface PostRequestOptions extends GetRequestOptions {\n body: string;\n}\n\nexport const Post = ({ url, credentials = 'include', headers, body }: PostRequestOptions) =>\n fetch(url, { method: 'POST', credentials, headers, body });\n\n/**\n * NodeJS 18 start using undici as http request handler,\n * undici http request does not accept invalid headers\n * for more details see:\n * https://github.com/nodejs/undici/blob/2b260c997ad4efe4ed2064b264b4b546a59e7a67/lib/core/request.js#L282\n * @param headers\n */\nexport function removeInvalidHeaders(headers: Record<string, string>) {\n const newHeaders = { ...headers };\n Object.keys(newHeaders).forEach((key: string) => {\n const val: any = headers[key];\n if (val && typeof val === 'object' && !Array.isArray(val)) {\n delete newHeaders[key];\n } else if (headerCharRegex.exec(val) !== null) {\n delete newHeaders[key];\n } else if (val === undefined || val === null) {\n delete newHeaders[key];\n } else if (key.length === 10 && key === 'connection') {\n delete newHeaders[key];\n }\n });\n return newHeaders;\n}\n\n/**\n * These header is used to identify the tenant for login per tenant feature\n */\nexport const CUSTOM_LOGIN_HEADER = 'frontegg-login-alias';\n\n/**\n * Build fetch request headers, remove invalid http headers\n * @param headers - Incoming request headers\n */\nexport function buildRequestHeaders(headers: Record<string, any>): Record<string, string> {\n let cookie = headers['cookie'];\n if (cookie != null && typeof cookie === 'string') {\n cookie = cookie.replace(/fe_session-[^=]*=[^;]*$/, '').replace(/fe_session-[^=]*=[^;]*;/, '');\n\n if (config.rewriteCookieByAppId && config.appId) {\n cookie = cookie\n .split(';')\n .filter((cookieStr: string) => !cookieStr.trim().startsWith(`fe_refresh_${config.clientId.replace('-', '')}`))\n .join(';');\n cookie = cookie.replace(\n `fe_refresh_${config.appId.replace('-', '')}`,\n `fe_refresh_${config.clientId.replace('-', '')}`\n );\n }\n }\n if (cookie != null && typeof cookie === 'object') {\n cookie = Object.entries(cookie)\n .filter(([key]) => {\n if (config.rewriteCookieByAppId && config.appId) {\n return key !== `fe_refresh_${config.clientId.replace('-', '')}`;\n }\n return true;\n })\n .map(([key, value]) => {\n if (config.rewriteCookieByAppId && config.appId && key === `fe_refresh_${config.appId.replace('-', '')}`) {\n return `fe_refresh_${config.clientId.replace('-', '')}=${value}`;\n } else {\n return `${key}=${value}`;\n }\n })\n .join('; ');\n }\n\n const preparedHeaders: Record<string, string> = {\n authorization: headers['authorization'],\n 'accept-encoding': headers['accept-encoding'],\n 'accept-language': headers['accept-language'],\n accept: headers['accept'],\n 'content-type': 'application/json',\n origin: config.baseUrl,\n cookie,\n 'user-agent': headers['user-agent'],\n 'cache-control': headers['cache-control'],\n 'x-frontegg-framework': `next@${nextjsPkg.version}`,\n 'x-frontegg-sdk': `@frontegg/nextjs@${sdkVersion.version}`,\n };\n\n if (headers['frontegg-requested-application-id']) {\n preparedHeaders['frontegg-requested-application-id'] = headers['frontegg-requested-application-id'];\n }\n\n const clientIp = headers['cf-connecting-ip'] || headers['x-original-forwarded-for'] || headers['x-forwarded-for'];\n if (clientIp) {\n preparedHeaders['x-original-forwarded-for'] = clientIp;\n }\n\n if (headers[CUSTOM_LOGIN_HEADER]) {\n preparedHeaders[CUSTOM_LOGIN_HEADER] = headers[CUSTOM_LOGIN_HEADER];\n }\n return removeInvalidHeaders({ ...preparedHeaders });\n}\n\n/**\n * Return parsed json response if http status code = 200\n * @param res\n */\nexport const parseHttpResponse = async <T>(res: Response): Promise<T | undefined> => {\n if (!res.ok) {\n return undefined;\n }\n return await res.json();\n};\n\n/**\n * Checks if the given path should be forwarded to the Next.js server middleware.\n *\n *\n * @param {string} path - The path to check for authentication API routes.\n * @returns {boolean} Returns true if the path is a frontegg authentication API route or ends with '/postlogin' or '/prelogin'; otherwise, returns false.\n */\nexport function isMiddlewarePath(path: string): boolean {\n let isAuthPath =\n fronteggAuthApiRoutesRegex.find((pathRegex) => {\n if (typeof pathRegex === 'string') {\n return pathRegex === path;\n } else {\n return new RegExp(pathRegex).test(path);\n }\n }) != null;\n\n // if(!isAuthPath){\n // isAuthPath = /^\\/identity\\/resources\\/auth\\/v[0-9]*\\/user\\/sso\\/[^\\/]*\\/postlogin$/g.test(path)\n // }\n // if(!isAuthPath){\n // isAuthPath = /^\\/identity\\/resources\\/auth\\/v[0-9]*\\/passwordless\\/[^\\/]*\\/prelogin$/g.test(path)\n // }\n // if(!isAuthPath){\n // isAuthPath = /^\\/identity\\/resources\\/auth\\/v[0-9]*\\/[^\\/]*\\/prelogin$/g.test(path)\n // }\n\n if (!isAuthPath) {\n const isSocialLoginPath = /^\\/identity\\/resources\\/auth\\/v[0-9]*\\/user\\/sso\\/default\\/[^\\/]*\\/prelogin$/.test(path);\n isAuthPath = (path.endsWith('/postlogin') || path.endsWith('/prelogin')) && !isSocialLoginPath;\n }\n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I;;EAEZ;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA,IAAI,CAACC,UAAU,EAAE;IACf,MAAMM,iBAAiB,GAAG,8EAA8E,CAACD,IAAI,CAACN,IAAI,CAAC;IACnHC,UAAU,GAAG,CAACD,IAAI,CAACQ,QAAQ,CAAC,YAAY,CAAC,IAAIR,IAAI,CAACQ,QAAQ,CAAC,WAAW,CAAC,KAAK,CAACD,iBAAiB;EAChG;EAEA,OAAON,UAAU;AACnB"}
@@ -25,7 +25,7 @@ const FronteggAppProvider = async options => {
25
25
  appEnvConfig = (0, _objectWithoutPropertiesLoose2.default)(_config$appEnvConfig, _excluded);
26
26
  let userData = await (0, _fetchUserData.default)({
27
27
  getSession: _helpers.getAppSession,
28
- getHeaders: _helpers.getAppHeadersPromise
28
+ getHeaders: _helpers.getAppHeaders
29
29
  });
30
30
  const subDomainAppUrl = await (0, _getAppUrlForCustomLoginWithSubdomain.getAppUrlForCustomLoginWithSubdomain)((_options$customLoginO = options.customLoginOptions) == null ? void 0 : _options$customLoginO.subDomainIndex);
31
31
  if (process.env['FRONTEGG_SECURE_JWT_ENABLED'] === 'true' && userData) {
@@ -1 +1 @@
1
- {"version":3,"file":"FronteggAppProvider.js","names":["_react","_interopRequireDefault","require","_ClientFronteggProvider","_helpers","_config","_fetchUserData","_getAppUrlForCustomLoginWithSubdomain","_helpers2","_jsxRuntime","_excluded","FronteggAppProvider","options","_options$customLoginO","_options$secureJwtEna","_config$appEnvConfig","config","appEnvConfig","envAppUrl","_objectWithoutPropertiesLoose2","default","userData","fetchUserData","getSession","getAppSession","getHeaders","getAppHeadersPromise","subDomainAppUrl","getAppUrlForCustomLoginWithSubdomain","customLoginOptions","subDomainIndex","process","env","_userData","removeJwtSignatureFrom","session","providerProps","_extends2","secureJwtEnabled","jsx","ClientFronteggProvider","exports"],"sources":["../../../../packages/nextjs/src/app/FronteggAppProvider.tsx"],"sourcesContent":["import React, { PropsWithChildren } from 'react';\nimport { ClientFronteggProvider } from './ClientFronteggProvider';\nimport { getAppHeadersPromise, getAppSession } from './helpers';\nimport config from '../config';\nimport fetchUserData from '../utils/fetchUserData';\nimport { ClientFronteggProviderProps } from '../types';\nimport { getAppUrlForCustomLoginWithSubdomain } from './getAppUrlForCustomLoginWithSubdomain';\nimport { removeJwtSignatureFrom } from '../middleware/helpers';\n\nexport type FronteggAppProviderProps = PropsWithChildren<\n Omit<ClientFronteggProviderProps, 'contextOptions' | 'envAppUrl' | 'envBaseUrl' | 'envClientId'>\n>;\n\nexport const FronteggAppProvider = async (options: FronteggAppProviderProps) => {\n const { envAppUrl, ...appEnvConfig } = config.appEnvConfig;\n let userData = await fetchUserData({ getSession: getAppSession, getHeaders: getAppHeadersPromise });\n const subDomainAppUrl = await getAppUrlForCustomLoginWithSubdomain(options.customLoginOptions?.subDomainIndex);\n\n if (process.env['FRONTEGG_SECURE_JWT_ENABLED'] === 'true' && userData) {\n userData = removeJwtSignatureFrom(userData);\n userData.session = removeJwtSignatureFrom(userData?.session);\n }\n const providerProps = {\n ...appEnvConfig,\n ...userData,\n ...options,\n envAppUrl: subDomainAppUrl ?? envAppUrl,\n secureJwtEnabled: options.secureJwtEnabled ?? false,\n };\n\n return <ClientFronteggProvider {...providerProps} />;\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,cAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEA,IAAAK,qCAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAA+D,IAAAO,WAAA,GAAAP,OAAA;AAAA,MAAAQ,SAAA;AAMxD,MAAMC,mBAAmB,GAAG,MAAOC,OAAiC,IAAK;EAAA,IAAAC,qBAAA,EAAAC,qBAAA;EAC9E,MAAAC,oBAAA,GAAuCC,eAAM,CAACC,YAAY;IAApD;MAAEC;IAA2B,CAAC,GAAAH,oBAAA;IAAdE,YAAY,OAAAE,8BAAA,CAAAC,OAAA,EAAAL,oBAAA,EAAAL,SAAA;EAClC,IAAIW,QAAQ,GAAG,MAAM,IAAAC,sBAAa,EAAC;IAAEC,UAAU,EAAEC,sBAAa;IAAEC,UAAU,EAAEC;EAAqB,CAAC,CAAC;EACnG,MAAMC,eAAe,GAAG,MAAM,IAAAC,0EAAoC,GAAAf,qBAAA,GAACD,OAAO,CAACiB,kBAAkB,qBAA1BhB,qBAAA,CAA4BiB,cAAc,CAAC;EAE9G,IAAIC,OAAO,CAACC,GAAG,CAAC,6BAA6B,CAAC,KAAK,MAAM,IAAIX,QAAQ,EAAE;IAAA,IAAAY,SAAA;IACrEZ,QAAQ,GAAG,IAAAa,gCAAsB,EAACb,QAAQ,CAAC;IAC3CA,QAAQ,CAACc,OAAO,GAAG,IAAAD,gCAAsB,GAAAD,SAAA,GAACZ,QAAQ,qBAARY,SAAA,CAAUE,OAAO,CAAC;EAC9D;EACA,MAAMC,aAAa,OAAAC,SAAA,CAAAjB,OAAA,MACdH,YAAY,EACZI,QAAQ,EACRT,OAAO;IACVM,SAAS,EAAES,eAAe,WAAfA,eAAe,GAAIT,SAAS;IACvCoB,gBAAgB,GAAAxB,qBAAA,GAAEF,OAAO,CAAC0B,gBAAgB,YAAAxB,qBAAA,GAAI;EAAK,EACpD;EAED,oBAAO,IAAAL,WAAA,CAAA8B,GAAA,EAACpC,uBAAA,CAAAqC,sBAAsB,MAAAH,SAAA,CAAAjB,OAAA,MAAKgB,aAAa,EAAI;AACtD,CAAC;AAACK,OAAA,CAAA9B,mBAAA,GAAAA,mBAAA"}
1
+ {"version":3,"file":"FronteggAppProvider.js","names":["_react","_interopRequireDefault","require","_ClientFronteggProvider","_helpers","_config","_fetchUserData","_getAppUrlForCustomLoginWithSubdomain","_helpers2","_jsxRuntime","_excluded","FronteggAppProvider","options","_options$customLoginO","_options$secureJwtEna","_config$appEnvConfig","config","appEnvConfig","envAppUrl","_objectWithoutPropertiesLoose2","default","userData","fetchUserData","getSession","getAppSession","getHeaders","getAppHeaders","subDomainAppUrl","getAppUrlForCustomLoginWithSubdomain","customLoginOptions","subDomainIndex","process","env","_userData","removeJwtSignatureFrom","session","providerProps","_extends2","secureJwtEnabled","jsx","ClientFronteggProvider","exports"],"sources":["../../../../packages/nextjs/src/app/FronteggAppProvider.tsx"],"sourcesContent":["import React, { PropsWithChildren } from 'react';\nimport { ClientFronteggProvider } from './ClientFronteggProvider';\nimport { getAppHeaders, getAppSession } from './helpers';\nimport config from '../config';\nimport fetchUserData from '../utils/fetchUserData';\nimport { ClientFronteggProviderProps } from '../types';\nimport { getAppUrlForCustomLoginWithSubdomain } from './getAppUrlForCustomLoginWithSubdomain';\nimport { removeJwtSignatureFrom } from '../middleware/helpers';\n\nexport type FronteggAppProviderProps = PropsWithChildren<\n Omit<ClientFronteggProviderProps, 'contextOptions' | 'envAppUrl' | 'envBaseUrl' | 'envClientId'>\n>;\n\nexport const FronteggAppProvider = async (options: FronteggAppProviderProps) => {\n const { envAppUrl, ...appEnvConfig } = config.appEnvConfig;\n let userData = await fetchUserData({ getSession: getAppSession, getHeaders: getAppHeaders });\n const subDomainAppUrl = await getAppUrlForCustomLoginWithSubdomain(options.customLoginOptions?.subDomainIndex);\n\n if (process.env['FRONTEGG_SECURE_JWT_ENABLED'] === 'true' && userData) {\n userData = removeJwtSignatureFrom(userData);\n userData.session = removeJwtSignatureFrom(userData?.session);\n }\n const providerProps = {\n ...appEnvConfig,\n ...userData,\n ...options,\n envAppUrl: subDomainAppUrl ?? envAppUrl,\n secureJwtEnabled: options.secureJwtEnabled ?? false,\n };\n\n return <ClientFronteggProvider {...providerProps} />;\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,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AAA8B,GAAA,EAACpC,uBAAA,CAAAqC,sBAAsB,MAAAH,SAAA,CAAAjB,OAAA,MAAKgB,aAAa,EAAI;AACtD,CAAC;AAACK,OAAA,CAAA9B,mBAAA,GAAAA,mBAAA"}
@@ -7,4 +7,11 @@ interface FronteggRouterProps {
7
7
  searchParams?: ParsedUrlQuery;
8
8
  }
9
9
  export declare function FronteggAppRouter(props: FronteggRouterProps): JSX.Element | null;
10
+ interface FronteggRouterAsyncProps {
11
+ params: Promise<ParsedUrlQuery & {
12
+ 'frontegg-router'?: string[];
13
+ }>;
14
+ searchParams?: Promise<ParsedUrlQuery>;
15
+ }
16
+ export declare function FronteggAppRouterAsync(props: FronteggRouterAsyncProps): Promise<JSX.Element | null>;
10
17
  export {};
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.FronteggAppRouter = FronteggAppRouter;
8
+ exports.FronteggAppRouterAsync = FronteggAppRouterAsync;
8
9
  var _navigation = require("next/navigation");
9
10
  var _routing = require("../utils/routing");
10
11
  var _FronteggRouterBase = require("../common/FronteggRouterBase");
@@ -37,4 +38,28 @@ function FronteggAppRouter(props) {
37
38
  isAppDirEnabled: true
38
39
  });
39
40
  }
41
+ async function FronteggAppRouterAsync(props) {
42
+ const params = await props.params;
43
+ const searchParams = await props.searchParams;
44
+ const pathArr = params['frontegg-router'] || [];
45
+ let pathname = `/${pathArr.join('/')}`;
46
+ if (!pathname || pathname.startsWith('/_next/data')) {
47
+ if (searchParams) {
48
+ const query = searchParams[Object.keys(searchParams)[0]];
49
+ pathname = `/${Array.isArray(query) ? query.join('/') : query}`;
50
+ } else {
51
+ (0, _navigation.notFound)();
52
+ return null;
53
+ }
54
+ }
55
+ if (!(0, _routing.isAuthRoute)(pathname)) {
56
+ (0, _navigation.notFound)();
57
+ return null;
58
+ }
59
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_FronteggRouterBase.FronteggRouterBase, {
60
+ pathArr: pathArr,
61
+ queryParams: searchParams,
62
+ isAppDirEnabled: true
63
+ });
64
+ }
40
65
  //# sourceMappingURL=FronteggAppRouter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FronteggAppRouter.js","names":["_navigation","require","_routing","_FronteggRouterBase","_react","_interopRequireDefault","_jsxRuntime","FronteggAppRouter","props","params","pathArr","searchParams","pathname","join","startsWith","query","Object","keys","Array","isArray","notFound","isAuthRoute","jsx","FronteggRouterBase","queryParams","isAppDirEnabled"],"sources":["../../../../packages/nextjs/src/app/FronteggAppRouter.tsx"],"sourcesContent":["import { notFound } from 'next/navigation';\nimport { ParsedUrlQuery } from 'querystring';\nimport { isAuthRoute } from '../utils/routing';\nimport { FronteggRouterBase } from '../common/FronteggRouterBase';\nimport React from 'react';\n\ninterface FronteggRouterProps {\n params: ParsedUrlQuery & { 'frontegg-router'?: string[] };\n searchParams?: ParsedUrlQuery;\n}\n\nexport function FronteggAppRouter(props: FronteggRouterProps) {\n const {\n params: { 'frontegg-router': pathArr = [] },\n searchParams,\n } = props;\n\n let pathname = `/${pathArr.join('/')}`;\n if (!pathname || pathname.startsWith('/_next/data')) {\n if (searchParams) {\n const query = searchParams[Object.keys(searchParams)[0]];\n pathname = `/${Array.isArray(query) ? query.join('/') : query}`;\n } else {\n notFound();\n return null;\n }\n }\n\n if (!isAuthRoute(pathname)) {\n notFound();\n return null;\n }\n\n return <FronteggRouterBase pathArr={pathArr} queryParams={searchParams} isAppDirEnabled />;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAA0B,IAAAK,WAAA,GAAAL,OAAA;AAOnB,SAASM,iBAAiBA,CAACC,KAA0B,EAAE;EAC5D,MAAM;IACJC,MAAM,EAAE;MAAE,iBAAiB,EAAEC,OAAO,GAAG;IAAG,CAAC;IAC3CC;EACF,CAAC,GAAGH,KAAK;EAET,IAAII,QAAQ,GAAI,IAAGF,OAAO,CAACG,IAAI,CAAC,GAAG,CAAE,EAAC;EACtC,IAAI,CAACD,QAAQ,IAAIA,QAAQ,CAACE,UAAU,CAAC,aAAa,CAAC,EAAE;IACnD,IAAIH,YAAY,EAAE;MAChB,MAAMI,KAAK,GAAGJ,YAAY,CAACK,MAAM,CAACC,IAAI,CAACN,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;MACxDC,QAAQ,GAAI,IAAGM,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,GAAGA,KAAK,CAACF,IAAI,CAAC,GAAG,CAAC,GAAGE,KAAM,EAAC;IACjE,CAAC,MAAM;MACL,IAAAK,oBAAQ,GAAE;MACV,OAAO,IAAI;IACb;EACF;EAEA,IAAI,CAAC,IAAAC,oBAAW,EAACT,QAAQ,CAAC,EAAE;IAC1B,IAAAQ,oBAAQ,GAAE;IACV,OAAO,IAAI;EACb;EAEA,oBAAO,IAAAd,WAAA,CAAAgB,GAAA,EAACnB,mBAAA,CAAAoB,kBAAkB;IAACb,OAAO,EAAEA,OAAQ;IAACc,WAAW,EAAEb,YAAa;IAACc,eAAe;EAAA,EAAG;AAC5F"}
1
+ {"version":3,"file":"FronteggAppRouter.js","names":["_navigation","require","_routing","_FronteggRouterBase","_react","_interopRequireDefault","_jsxRuntime","FronteggAppRouter","props","params","pathArr","searchParams","pathname","join","startsWith","query","Object","keys","Array","isArray","notFound","isAuthRoute","jsx","FronteggRouterBase","queryParams","isAppDirEnabled","FronteggAppRouterAsync"],"sources":["../../../../packages/nextjs/src/app/FronteggAppRouter.tsx"],"sourcesContent":["import { notFound } from 'next/navigation';\nimport { ParsedUrlQuery } from 'querystring';\nimport { isAuthRoute } from '../utils/routing';\nimport { FronteggRouterBase } from '../common/FronteggRouterBase';\nimport React from 'react';\n\ninterface FronteggRouterProps {\n params: ParsedUrlQuery & { 'frontegg-router'?: string[] };\n searchParams?: ParsedUrlQuery;\n}\n\nexport function FronteggAppRouter(props: FronteggRouterProps) {\n const {\n params: { 'frontegg-router': pathArr = [] },\n searchParams,\n } = props;\n\n let pathname = `/${pathArr.join('/')}`;\n if (!pathname || pathname.startsWith('/_next/data')) {\n if (searchParams) {\n const query = searchParams[Object.keys(searchParams)[0]];\n pathname = `/${Array.isArray(query) ? query.join('/') : query}`;\n } else {\n notFound();\n return null;\n }\n }\n\n if (!isAuthRoute(pathname)) {\n notFound();\n return null;\n }\n\n return <FronteggRouterBase pathArr={pathArr} queryParams={searchParams} isAppDirEnabled />;\n}\n\ninterface FronteggRouterAsyncProps {\n params: Promise<ParsedUrlQuery & { 'frontegg-router'?: string[] }>;\n searchParams?: Promise<ParsedUrlQuery>;\n}\nexport async function FronteggAppRouterAsync(props: FronteggRouterAsyncProps) {\n const params = await props.params;\n const searchParams = await props.searchParams;\n\n const pathArr = params['frontegg-router'] || [];\n\n let pathname = `/${pathArr.join('/')}`;\n if (!pathname || pathname.startsWith('/_next/data')) {\n if (searchParams) {\n const query = searchParams[Object.keys(searchParams)[0]];\n pathname = `/${Array.isArray(query) ? query.join('/') : query}`;\n } else {\n notFound();\n return null;\n }\n }\n\n if (!isAuthRoute(pathname)) {\n notFound();\n return null;\n }\n\n return <FronteggRouterBase pathArr={pathArr} queryParams={searchParams} isAppDirEnabled />;\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAA0B,IAAAK,WAAA,GAAAL,OAAA;AAOnB,SAASM,iBAAiBA,CAACC,KAA0B,EAAE;EAC5D,MAAM;IACJC,MAAM,EAAE;MAAE,iBAAiB,EAAEC,OAAO,GAAG;IAAG,CAAC;IAC3CC;EACF,CAAC,GAAGH,KAAK;EAET,IAAII,QAAQ,GAAI,IAAGF,OAAO,CAACG,IAAI,CAA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CAAC,GAAGA,KAAK,CAACF,IAAI,CAAC,GAAG,CAAC,GAAGE,KAAM,EAAC;IACjE,CAAC,MAAM;MACL,IAAAK,oBAAQ,GAAE;MACV,OAAO,IAAI;IACb;EACF;EAEA,IAAI,CAAC,IAAAC,oBAAW,EAACT,QAAQ,CAAC,EAAE;IAC1B,IAAAQ,oBAAQ,GAAE;IACV,OAAO,IAAI;EACb;EAEA,oBAAO,IAAAd,WAAA,CAAAgB,GAAA,EAACnB,mBAAA,CAAAoB,kBAAkB;IAACb,OAAO,EAAEA,OAAQ;IAACc,WAAW,EAAEb,YAAa;IAACc,eAAe;EAAA,EAAG;AAC5F"}
@@ -38,7 +38,7 @@ const getAppUrlForCustomLoginWithSubdomain = async subDomainIndex => {
38
38
  if (subDomainIndex === undefined) {
39
39
  return undefined;
40
40
  }
41
- const headers = (0, _helpers.getAppHeaders)();
41
+ const headers = await (0, _helpers.getAppHeaders)();
42
42
  const alias = getTenantAliasFromHeaders(headers, subDomainIndex);
43
43
  if (!alias) {
44
44
  resetGlobalCustomLoginAppUrl();
@@ -1 +1 @@
1
- {"version":3,"file":"getAppUrlForCustomLoginWithSubdomain.js","names":["_api","require","_utils","_helpers","getTenantAliasFromHeaders","headers","subDomainIndex","_headers$host","_headers$host$split","_headers$host$split$s","host","split","slice","exports","resetGlobalCustomLoginAppUrl","global","customLoginAppUrl","undefined","getAppUrlForCustomLoginWithSubdomain","getAppHeaders","alias","requestHeaders","_extends2","default","CUSTOM_LOGIN_HEADER","res","getPublicSettings","catch","subDomainAppUrl","applicationUrl"],"sources":["../../../../packages/nextjs/src/app/getAppUrlForCustomLoginWithSubdomain.ts"],"sourcesContent":["import { getPublicSettings } from '../api';\nimport { CUSTOM_LOGIN_HEADER } from '../api/utils';\nimport { getAppHeaders } from './helpers';\n\n/**\n * get the tenant alias from the request headers with the host and subdomain index\n * @param headers - the request headers\n * @param subDomainIndex - the subdomain index to specify the tenant sub-domain\n * @returns the alias for custom login with subdomain or undefined if not exist\n */\nexport const getTenantAliasFromHeaders = (headers: Record<string, string>, subDomainIndex: number) => {\n return headers?.host?.split('.')?.slice(0, -2)?.[subDomainIndex];\n};\n\n/**\n * set the global.customLoginAppUrl to undefined in order to allow switching from tenant to vendor app\n */\nexport const resetGlobalCustomLoginAppUrl = () => {\n global.customLoginAppUrl = undefined;\n};\n\n/**\n * get the app url for custom login with subdomain and set it to the global customLoginAppUrl\n * @param subDomainIndex - the index of the subdomain in the host\n * @returns Promise of string or undefined, the app url for custom login with subdomain or undefined if the sub-domain index/app url/alias is not exist\n * @sideEffect - set the global.customLoginAppUrl to the app url for custom login with subdomain */\n\nexport const getAppUrlForCustomLoginWithSubdomain = async (subDomainIndex?: number): Promise<string | undefined> => {\n if (subDomainIndex === undefined) {\n return undefined;\n }\n\n const headers = getAppHeaders();\n const alias = getTenantAliasFromHeaders(headers, subDomainIndex);\n if (!alias) {\n resetGlobalCustomLoginAppUrl();\n return undefined;\n }\n const requestHeaders = { ...headers, [CUSTOM_LOGIN_HEADER]: alias };\n const res = await getPublicSettings(requestHeaders).catch(() => undefined);\n const subDomainAppUrl = res?.applicationUrl;\n if (!subDomainAppUrl) {\n resetGlobalCustomLoginAppUrl();\n return undefined;\n }\n global.customLoginAppUrl = subDomainAppUrl;\n return subDomainAppUrl;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,yBAAyB,GAAGA,CAACC,OAA+B,EAAEC,cAAsB,KAAK;EAAA,IAAAC,aAAA,EAAAC,mBAAA,EAAAC,qBAAA;EACpG,OAAOJ,OAAO,qBAAAE,aAAA,GAAPF,OAAO,CAAEK,IAAI,sBAAAF,mBAAA,GAAbD,aAAA,CAAeI,KAAK,CAAC,GAAG,CAAC,sBAAAF,qBAAA,GAAzBD,mBAAA,CAA2BI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,qBAAvCH,qBAAA,CAA0CH,cAAc,CAAC;AAClE,CAAC;;AAED;AACA;AACA;AAFAO,OAAA,CAAAT,yBAAA,GAAAA,yBAAA;AAGO,MAAMU,4BAA4B,GAAGA,CAAA,KAAM;EAChDC,MAAM,CAACC,iBAAiB,GAAGC,SAAS;AACtC,CAAC;;AAED;AACA;AACA;AACA;AACA;AAJAJ,OAAA,CAAAC,4BAAA,GAAAA,4BAAA;AAMO,MAAMI,oCAAoC,GAAG,MAAOZ,cAAuB,IAAkC;EAClH,IAAIA,cAAc,KAAKW,SAAS,EAAE;IAChC,OAAOA,SAAS;EAClB;EAEA,MAAMZ,OAAO,GAAG,IAAAc,sBAAa,GAAE;EAC/B,MAAMC,KAAK,GAAGhB,yBAAyB,CAACC,OAAO,EAAEC,cAAc,CAAC;EAChE,IAAI,CAACc,KAAK,EAAE;IACVN,4BAA4B,EAAE;IAC9B,OAAOG,SAAS;EAClB;EACA,MAAMI,cAAc,OAAAC,SAAA,CAAAC,OAAA,MAAQlB,OAAO;IAAE,CAACmB,0BAAmB,GAAGJ;EAAK,EAAE;EACnE,MAAMK,GAAG,GAAG,MAAM,IAAAC,sBAAiB,EAACL,cAAc,CAAC,CAACM,KAAK,CAAC,MAAMV,SAAS,CAAC;EAC1E,MAAMW,eAAe,GAAGH,GAAG,oBAAHA,GAAG,CAAEI,cAAc;EAC3C,IAAI,CAACD,eAAe,EAAE;IACpBd,4BAA4B,EAAE;IAC9B,OAAOG,SAAS;EAClB;EACAF,MAAM,CAACC,iBAAiB,GAAGY,eAAe;EAC1C,OAAOA,eAAe;AACxB,CAAC;AAACf,OAAA,CAAAK,oCAAA,GAAAA,oCAAA"}
1
+ {"version":3,"file":"getAppUrlForCustomLoginWithSubdomain.js","names":["_api","require","_utils","_helpers","getTenantAliasFromHeaders","headers","subDomainIndex","_headers$host","_headers$host$split","_headers$host$split$s","host","split","slice","exports","resetGlobalCustomLoginAppUrl","global","customLoginAppUrl","undefined","getAppUrlForCustomLoginWithSubdomain","getAppHeaders","alias","requestHeaders","_extends2","default","CUSTOM_LOGIN_HEADER","res","getPublicSettings","catch","subDomainAppUrl","applicationUrl"],"sources":["../../../../packages/nextjs/src/app/getAppUrlForCustomLoginWithSubdomain.ts"],"sourcesContent":["import { getPublicSettings } from '../api';\nimport { CUSTOM_LOGIN_HEADER } from '../api/utils';\nimport { getAppHeaders } from './helpers';\n\n/**\n * get the tenant alias from the request headers with the host and subdomain index\n * @param headers - the request headers\n * @param subDomainIndex - the subdomain index to specify the tenant sub-domain\n * @returns the alias for custom login with subdomain or undefined if not exist\n */\nexport const getTenantAliasFromHeaders = (headers: Record<string, string>, subDomainIndex: number) => {\n return headers?.host?.split('.')?.slice(0, -2)?.[subDomainIndex];\n};\n\n/**\n * set the global.customLoginAppUrl to undefined in order to allow switching from tenant to vendor app\n */\nexport const resetGlobalCustomLoginAppUrl = () => {\n global.customLoginAppUrl = undefined;\n};\n\n/**\n * get the app url for custom login with subdomain and set it to the global customLoginAppUrl\n * @param subDomainIndex - the index of the subdomain in the host\n * @returns Promise of string or undefined, the app url for custom login with subdomain or undefined if the sub-domain index/app url/alias is not exist\n * @sideEffect - set the global.customLoginAppUrl to the app url for custom login with subdomain */\n\nexport const getAppUrlForCustomLoginWithSubdomain = async (subDomainIndex?: number): Promise<string | undefined> => {\n if (subDomainIndex === undefined) {\n return undefined;\n }\n\n const headers = await getAppHeaders();\n const alias = getTenantAliasFromHeaders(headers, subDomainIndex);\n if (!alias) {\n resetGlobalCustomLoginAppUrl();\n return undefined;\n }\n const requestHeaders = { ...headers, [CUSTOM_LOGIN_HEADER]: alias };\n const res = await getPublicSettings(requestHeaders).catch(() => undefined);\n const subDomainAppUrl = res?.applicationUrl;\n if (!subDomainAppUrl) {\n resetGlobalCustomLoginAppUrl();\n return undefined;\n }\n global.customLoginAppUrl = subDomainAppUrl;\n return subDomainAppUrl;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,IAAA,G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AG,oBAAHA,GAAG,CAAEI,cAAc;EAC3C,IAAI,CAACD,eAAe,EAAE;IACpBd,4BAA4B,EAAE;IAC9B,OAAOG,SAAS;EAClB;EACAF,MAAM,CAACC,iBAAiB,GAAGY,eAAe;EAC1C,OAAOA,eAAe;AACxB,CAAC;AAACf,OAAA,CAAAK,oCAAA,GAAAA,oCAAA"}
package/app/helpers.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { FronteggUserSession, FronteggUserTokens } from '../types';
2
+ /**
3
+ * Support for Next.js 15 breaking changes, where props.params is now a promise-based function
4
+ * for more info: https://nextjs.org/docs/messages/sync-dynamic-apis
5
+ * @param obj
6
+ * @param key
7
+ */
8
+ export declare function handleOptionalPromiseObject(obj: any, key: string): Promise<any>;
2
9
  export declare const getAppSession: () => Promise<import("../types").FronteggNextJSSession | undefined>;
3
- export declare const getAppHeaders: () => Record<string, string>;
4
- export declare const getAppHeadersPromise: () => Promise<Record<string, string>>;
10
+ export declare const getAppHeaders: () => Promise<Record<string, string>>;
5
11
  export declare function getAppUserSession(): Promise<FronteggUserSession | undefined>;
6
12
  export declare function getAppUserTokens(): Promise<FronteggUserTokens | undefined>;
package/app/helpers.js CHANGED
@@ -4,32 +4,77 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.getAppSession = exports.getAppHeadersPromise = exports.getAppHeaders = void 0;
7
+ exports.getAppSession = exports.getAppHeaders = void 0;
8
8
  exports.getAppUserSession = getAppUserSession;
9
9
  exports.getAppUserTokens = getAppUserTokens;
10
+ exports.handleOptionalPromiseObject = handleOptionalPromiseObject;
10
11
  var _headers = require("next/headers");
11
12
  var _cookies = _interopRequireDefault(require("../utils/cookies"));
12
13
  var _createSession = _interopRequireDefault(require("../utils/createSession"));
13
14
  var _encryption = _interopRequireDefault(require("../utils/encryption"));
14
- const getCookie = () => {
15
- const allCookies = (0, _headers.cookies)().getAll();
15
+ /**
16
+ * Support for Next.js 15 breaking changes, where props.params is now a promise-based function
17
+ * for more info: https://nextjs.org/docs/messages/sync-dynamic-apis
18
+ * @param obj
19
+ * @param key
20
+ */
21
+ async function handleOptionalPromiseObject(obj, key) {
22
+ let value;
23
+ if (typeof obj[key] === 'function') {
24
+ var _obj$key;
25
+ // In case props.params is now a promise-based function
26
+ value = await (obj == null ? void 0 : (_obj$key = obj[key]) == null ? void 0 : _obj$key.call(obj));
27
+ } else {
28
+ // If props.params is still an object
29
+ value = obj == null ? void 0 : obj[key];
30
+ }
31
+ return value;
32
+ }
33
+
34
+ /**
35
+ * Support for Next.js 15 breaking changes, where cookies() are now promise-based functions
36
+ * for more info: https://nextjs.org/docs/messages/sync-dynamic-apis
37
+ * @param func
38
+ */
39
+ async function getRequestCookies() {
40
+ let value = (0, _headers.cookies)();
41
+
42
+ // noinspection SuspiciousTypeOfGuard
43
+ if (value instanceof Promise) {
44
+ return await value;
45
+ }
46
+ return value;
47
+ }
48
+
49
+ /**
50
+ * Support for Next.js 15 breaking changes, where cookies() are now promise-based functions
51
+ * for more info: https://nextjs.org/docs/messages/sync-dynamic-apis
52
+ * @param func
53
+ */
54
+ async function getRequestHeaders() {
55
+ let value = (0, _headers.headers)();
56
+
57
+ // noinspection SuspiciousTypeOfGuard
58
+ if (value instanceof Promise) {
59
+ return await value;
60
+ }
61
+ return value;
62
+ }
63
+ const getCookie = async () => {
64
+ const allCookies = (await getRequestCookies()).getAll();
16
65
  return _cookies.default.parseCookieFromArray(allCookies);
17
66
  };
18
- const getAppSession = () => {
19
- const cookies = getCookie();
67
+ const getAppSession = async () => {
68
+ const cookies = await getCookie();
20
69
  return (0, _createSession.default)(cookies, _encryption.default);
21
70
  };
22
71
  exports.getAppSession = getAppSession;
23
- const getAppHeaders = () => {
72
+ const getAppHeaders = async () => {
24
73
  const reqHeaders = {};
25
- (0, _headers.headers)().forEach((value, key) => reqHeaders[key] = value);
74
+ (await getRequestHeaders()).forEach((value, key) => reqHeaders[key] = value);
26
75
  return reqHeaders;
27
76
  };
28
77
  exports.getAppHeaders = getAppHeaders;
29
- const getAppHeadersPromise = async () => {
30
- return getAppHeaders();
31
- };
32
- exports.getAppHeadersPromise = getAppHeadersPromise;
33
78
  async function getAppUserSession() {
34
79
  const session = await getAppSession();
35
80
  return session == null ? void 0 : session.user;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","names":["_headers","require","_cookies","_interopRequireDefault","_createSession","_encryption","getCookie","allCookies","cookies","getAll","CookieManager","parseCookieFromArray","getAppSession","createSession","encryption","exports","getAppHeaders","reqHeaders","headers","forEach","value","key","getAppHeadersPromise","getAppUserSession","session","user","getAppUserTokens","undefined","accessToken","refreshToken"],"sources":["../../../../packages/nextjs/src/app/helpers.ts"],"sourcesContent":["import { cookies, headers } from 'next/headers';\nimport CookieManager from '../utils/cookies';\nimport createSession from '../utils/createSession';\nimport encryption from '../utils/encryption';\nimport { FronteggUserSession, FronteggUserTokens } from '../types';\n\nconst getCookie = () => {\n const allCookies = cookies().getAll();\n return CookieManager.parseCookieFromArray(allCookies);\n};\n\nexport const getAppSession = () => {\n const cookies = getCookie();\n return createSession(cookies, encryption);\n};\n\nexport const getAppHeaders = (): Record<string, string> => {\n const reqHeaders: Record<string, string> = {};\n headers().forEach((value, key) => (reqHeaders[key] = value));\n return reqHeaders;\n};\n\nexport const getAppHeadersPromise = async (): Promise<Record<string, string>> => {\n return getAppHeaders();\n};\n\nexport async function getAppUserSession(): Promise<FronteggUserSession | undefined> {\n const session = await getAppSession();\n return session?.user;\n}\n\nexport async function getAppUserTokens(): Promise<FronteggUserTokens | undefined> {\n const session = await getAppSession();\n if (!session) {\n return undefined;\n }\n return {\n accessToken: session.accessToken,\n refreshToken: session.refreshToken,\n };\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,cAAA,GAAAD,sBAAA,CAAAF,O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","_createSession","_encryption","handleOptionalPromiseObject","obj","key","value","_obj$key","call","getRequestCookies","cookies","Promise","getRequestHeaders","headers","getCookie","allCookies","getAll","CookieManager","parseCookieFromArray","getAppSession","createSession","encryption","exports","getAppHeaders","reqHeaders","forEach","getAppUserSession","session","user","getAppUserTokens","undefined","accessToken","refreshToken"],"sources":["../../../../packages/nextjs/src/app/helpers.ts"],"sourcesContent":["import { cookies, headers } from 'next/headers';\nimport CookieManager from '../utils/cookies';\nimport createSession from '../utils/createSession';\nimport encryption from '../utils/encryption';\nimport { FronteggUserSession, FronteggUserTokens } from '../types';\n\n/**\n * Support for Next.js 15 breaking changes, where props.params is now a promise-based function\n * for more info: https://nextjs.org/docs/messages/sync-dynamic-apis\n * @param obj\n * @param key\n */\nexport async function handleOptionalPromiseObject(obj: any, key: string) {\n let value;\n\n if (typeof obj[key] === 'function') {\n // In case props.params is now a promise-based function\n value = await obj?.[key]?.();\n } else {\n // If props.params is still an object\n value = obj?.[key];\n }\n\n return value;\n}\n\n/**\n * Support for Next.js 15 breaking changes, where cookies() are now promise-based functions\n * for more info: https://nextjs.org/docs/messages/sync-dynamic-apis\n * @param func\n */\nasync function getRequestCookies() {\n let value = cookies();\n\n // noinspection SuspiciousTypeOfGuard\n if (value instanceof Promise) {\n return await value;\n }\n return value;\n}\n\n/**\n * Support for Next.js 15 breaking changes, where cookies() are now promise-based functions\n * for more info: https://nextjs.org/docs/messages/sync-dynamic-apis\n * @param func\n */\nasync function getRequestHeaders() {\n let value = headers();\n\n // noinspection SuspiciousTypeOfGuard\n if (value instanceof Promise) {\n return await value;\n }\n return value;\n}\n\nconst getCookie = async () => {\n const allCookies = (await getRequestCookies()).getAll();\n return CookieManager.parseCookieFromArray(allCookies);\n};\n\nexport const getAppSession = async () => {\n const cookies = await getCookie();\n return createSession(cookies, encryption);\n};\n\nexport const getAppHeaders = async (): Promise<Record<string, string>> => {\n const reqHeaders: Record<string, string> = {};\n (await getRequestHeaders()).forEach((value: string, key: string) => (reqHeaders[key] = value));\n return reqHeaders;\n};\n\nexport async function getAppUserSession(): Promise<FronteggUserSession | undefined> {\n const session = await getAppSession();\n return session?.user;\n}\n\nexport async function getAppUserTokens(): Promise<FronteggUserTokens | undefined> {\n const session = await getAppSession();\n if (!session) {\n return undefined;\n }\n return {\n accessToken: session.accessToken,\n refreshToken: session.refreshToken,\n };\n}\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,cAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,WAAA,GAAAF,sBAAA,CAAAF,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeK,2BAA2BA,CAACC,GAAQ,EAAEC,GAAW,EAAE;EACvE,IAAIC,KAAK;EAET,IAAI,OAAOF,GAAG,CAACC,GAAG,CAAC,KAAK,UAAU,EAAE;IAAA,IAAAE,QAAA;IAClC;IACAD,KAAK,GAAG,OAAMF,GAAG,qBAAAG,QAAA,GAAHH,GAAG,CAAGC,GAAG,CAAC,qBAAVE,QAAA,CAAAC,IAAA,CAAAJ,GAAG,CAAW;EAC9B,CAAC,MAAM;IACL;IACAE,KAAK,GAAGF,GAAG,oBAAHA,GAAG,CAAGC,GAAG,CAAC;EACpB;EAEA,OAAOC,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA,eAAeG,iBAAiBA,CAAA,EAAG;EACjC,IAAIH,KAAK,GAAG,IAAAI,gBAAO,GAAE;;EAErB;EACA,IAAIJ,KAAK,YAAYK,OAAO,EAAE;IAC5B,OAAO,MAAML,KAAK;EACpB;EACA,OAAOA,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA,eAAeM,iBAAiBA,CAAA,EAAG;EACjC,IAAIN,KAAK,GAAG,IAAAO,gBAAO,GAAE;;EAErB;EACA,IAAIP,KAAK,YAAYK,OAAO,EAAE;IAC5B,OAAO,MAAML,KAAK;EACpB;EACA,OAAOA,KAAK;AACd;AAEA,MAAMQ,SAAS,GAAG,MAAAA,CAAA,KAAY;EAC5B,MAAMC,UAAU,GAAG,CAAC,MAAMN,iBAAiB,EAAE,EAAEO,MAAM,EAAE;EACvD,OAAOC,gBAAa,CAACC,oBAAoB,CAACH,UAAU,CAAC;AACvD,CAAC;AAEM,MAAMI,aAAa,GAAG,MAAAA,CAAA,KAAY;EACvC,MAAMT,OAAO,GAAG,MAAMI,SAAS,EAAE;EACjC,OAAO,IAAAM,sBAAa,EAACV,OAAO,EAAEW,mBAAU,CAAC;AAC3C,CAAC;AAACC,OAAA,CAAAH,aAAA,GAAAA,aAAA;AAEK,MAAMI,aAAa,GAAG,MAAAA,CAAA,KAA6C;EACxE,MAAMC,UAAkC,GAAG,CAAC,CAAC;EAC7C,CAAC,MAAMZ,iBAAiB,EAAE,EAAEa,OAAO,CAAC,CAACnB,KAAa,EAAED,GAAW,KAAMmB,UAAU,CAACnB,GAAG,CAAC,GAAGC,KAAM,CAAC;EAC9F,OAAOkB,UAAU;AACnB,CAAC;AAACF,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAEK,eAAeG,iBAAiBA,CAAA,EAA6C;EAClF,MAAMC,OAAO,GAAG,MAAMR,aAAa,EAAE;EACrC,OAAOQ,OAAO,oBAAPA,OAAO,CAAEC,IAAI;AACtB;AAEO,eAAeC,gBAAgBA,CAAA,EAA4C;EAChF,MAAMF,OAAO,GAAG,MAAMR,aAAa,EAAE;EACrC,IAAI,CAACQ,OAAO,EAAE;IACZ,OAAOG,SAAS;EAClB;EACA,OAAO;IACLC,WAAW,EAAEJ,OAAO,CAACI,WAAW;IAChCC,YAAY,EAAEL,OAAO,CAACK;EACxB,CAAC;AACH"}
@@ -21,7 +21,7 @@ const _excluded = ["router", "appName"];
21
21
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
22
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
23
  const Connector = _ref => {
24
- var _props$basename, _props$authOptions;
24
+ var _props$basename, _props$authOptions, _session$accessToken;
25
25
  let {
26
26
  router,
27
27
  appName = 'default'
@@ -45,7 +45,9 @@ const Connector = _ref => {
45
45
  appName,
46
46
  storeHolder: storeHolder.current
47
47
  }), [props]);
48
- _restApi.ContextHolder.setOnRedirectTo(onRedirectTo);
48
+ _restApi.ContextHolder.for(appName).setOnRedirectTo(onRedirectTo);
49
+ _restApi.ContextHolder.for(appName).setAccessToken((_session$accessToken = session == null ? void 0 : session.accessToken) != null ? _session$accessToken : null);
50
+ _restApi.ContextHolder.for(appName).setUser(session == null ? void 0 : session['user']);
49
51
  (0, _useRequestAuthorizeSSR.default)({
50
52
  app,
51
53
  user,
@@ -1 +1 @@
1
- {"version":3,"file":"FronteggBaseProvider.js","names":["_interopRequireDefault","require","Object","defineProperty","exports","value","FronteggBaseProvider","_extends2","_objectWithoutPropertiesLoose2","_react","_interopRequireWildcard","_reactHooks","_restApi","_AppContext","_initializeFronteggApp","_useRequestAuthorizeSSR","_useOnRedirectTo","_config","_jsxRuntime","_excluded","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","Connector","_ref","_props$basename","_props$authOptions","router","appName","props","isSSR","window","user","session","tenants","activeTenant","baseName","basename","storeHolder","useRef","onRedirectTo","useOnRedirectTo","authOptions","routes","app","useMemo","initializeFronteggApp","options","current","ContextHolder","setOnRedirectTo","useRequestAuthorizeSSR","jsx","Provider","children","FronteggStoreProvider","alwaysVisibleChildren","CustomComponentRegister","themeOptions","config","fronteggAppOptions","framework"],"sources":["../../../../packages/nextjs/src/common/FronteggBaseProvider.tsx"],"sourcesContent":["'use client';\n\nimport React, { FC, useMemo, useRef } from 'react';\nimport { FronteggStoreProvider, CustomComponentRegister } from '@frontegg/react-hooks';\nimport { ContextHolder } from '@frontegg/rest-api';\nimport type { FronteggProviderProps } from '../types';\nimport AppContext from './AppContext';\nimport initializeFronteggApp from '../utils/initializeFronteggApp';\nimport useRequestAuthorizeSSR from './useRequestAuthorizeSSR';\nimport useOnRedirectTo from '../utils/useOnRedirectTo';\nimport config from '../config';\n\nconst Connector: FC<FronteggProviderProps> = ({ router, appName = 'default', ...props }) => {\n const isSSR = typeof window === 'undefined';\n const { user, session, tenants, activeTenant } = props;\n const baseName = props.basename ?? '';\n const storeHolder = useRef({});\n\n const onRedirectTo = useOnRedirectTo(baseName, router, props.authOptions?.routes);\n\n const app = useMemo(\n () =>\n initializeFronteggApp({\n options: { ...props, basename: baseName },\n onRedirectTo,\n appName,\n storeHolder: storeHolder.current,\n }),\n [props]\n );\n ContextHolder.setOnRedirectTo(onRedirectTo);\n\n useRequestAuthorizeSSR({ app, user, tenants, activeTenant, session });\n return (\n <AppContext.Provider value={app}>\n <FronteggStoreProvider\n {...({ ...props, app } as any)}\n alwaysVisibleChildren={!isSSR && <CustomComponentRegister app={app} themeOptions={props.themeOptions} />}\n >\n {props.children}\n </FronteggStoreProvider>\n </AppContext.Provider>\n );\n};\n\nexport const FronteggBaseProvider: FC<FronteggProviderProps> = (props) => {\n config.fronteggAppOptions = props ?? {};\n\n return (\n <Connector {...props} framework={'nextjs'}>\n {props.children}\n </Connector>\n );\n};\n"],"mappings":";AAAA,YAAY;;AAAC,IAAAA,sBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,cAAA,CAAAC,OAAA;EAAAC,KAAA;AAAA;AAAAD,OAAA,CAAAE,oBAAA;AAAA,IAAAC,SAAA,GAAAP,sBAAA,CAAAC,OAAA;AAAA,IAAAO,8BAAA,GAAAR,sBAAA,CAAAC,OAAA;AAEb,IAAAQ,MAAA,GAAAC,uBAAA,CAAAT,OAAA;AACA,IAAAU,WAAA,GAAAV,OAAA;AACA,IAAAW,QAAA,GAAAX,OAAA;AAEA,IAAAY,WAAA,GAAAb,sBAAA,CAAAC,OAAA;AACA,IAAAa,sBAAA,GAAAd,sBAAA,CAAAC,OAAA;AACA,IAAAc,uBAAA,GAAAf,sBAAA,CAAAC,OAAA;AACA,IAAAe,gBAAA,GAAAhB,sBAAA,CAAAC,OAAA;AACA,IAAAgB,OAAA,GAAAjB,sBAAA,CAAAC,OAAA;AAA+B,IAAAiB,WAAA,GAAAjB,OAAA;AAAA,MAAAkB,SAAA;AAAA,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAX,wBAAAe,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CA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vCzB,KAAK,CAACyB;EAAQ,GACL;AAEhB,CAAC;AAACnE,OAAA,CAAAE,oBAAA,GAAAA,oBAAA"}
1
+ {"version":3,"file":"FronteggBaseProvider.js","names":["_interopRequireDefault","require","Object","defineProperty","exports","value","FronteggBaseProvider","_extends2","_objectWithoutPropertiesLoose2","_react","_interopRequireWildcard","_reactHooks","_restApi","_AppContext","_initializeFronteggApp","_useRequestAuthorizeSSR","_useOnRedirectTo","_config","_jsxRuntime","_excluded","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","Connector","_ref","_props$basename","_props$authOptions","_session$accessToken","router","appName","props","isSSR","window","user","session","tenants","activeTenant","baseName","basename","storeHolder","useRef","onRedirectTo","useOnRedirectTo","authOptions","routes","app","useMemo","initializeFronteggApp","options","current","ContextHolder","for","setOnRedirectTo","setAccessToken","accessToken","setUser","useRequestAuthorizeSSR","jsx","Provider","children","FronteggStoreProvider","alwaysVisibleChildren","CustomComponentRegister","themeOptions","config","fronteggAppOptions","framework"],"sources":["../../../../packages/nextjs/src/common/FronteggBaseProvider.tsx"],"sourcesContent":["'use client';\n\nimport React, { FC, useMemo, useRef } from 'react';\nimport { FronteggStoreProvider, CustomComponentRegister } from '@frontegg/react-hooks';\nimport { ContextHolder, IUserProfile } from '@frontegg/rest-api';\nimport type { FronteggProviderProps } from '../types';\nimport AppContext from './AppContext';\nimport initializeFronteggApp from '../utils/initializeFronteggApp';\nimport useRequestAuthorizeSSR from './useRequestAuthorizeSSR';\nimport useOnRedirectTo from '../utils/useOnRedirectTo';\nimport config from '../config';\n\nconst Connector: FC<FronteggProviderProps> = ({ router, appName = 'default', ...props }) => {\n const isSSR = typeof window === 'undefined';\n const { user, session, tenants, activeTenant } = props;\n const baseName = props.basename ?? '';\n const storeHolder = useRef({});\n\n const onRedirectTo = useOnRedirectTo(baseName, router, props.authOptions?.routes);\n\n const app = useMemo(\n () =>\n initializeFronteggApp({\n options: { ...props, basename: baseName },\n onRedirectTo,\n appName,\n storeHolder: storeHolder.current,\n }),\n [props]\n );\n ContextHolder.for(appName).setOnRedirectTo(onRedirectTo);\n\n ContextHolder.for(appName).setAccessToken(session?.accessToken ?? null);\n ContextHolder.for(appName).setUser(session?.['user'] as any);\n useRequestAuthorizeSSR({ app, user, tenants, activeTenant, session });\n return (\n <AppContext.Provider value={app}>\n <FronteggStoreProvider\n {...({ ...props, app } as any)}\n alwaysVisibleChildren={!isSSR && <CustomComponentRegister app={app} themeOptions={props.themeOptions} />}\n >\n {props.children}\n </FronteggStoreProvider>\n </AppContext.Provider>\n );\n};\n\nexport const FronteggBaseProvider: FC<FronteggProviderProps> = (props) => {\n config.fronteggAppOptions = props ?? {};\n\n return (\n <Connector {...props} framework={'nextjs'}>\n {props.children}\n </Connector>\n );\n};\n"],"mappings":";AAAA,YAAY;;AAAC,IAAAA,sBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,cAAA,CAAAC,OAAA;EAAAC,KAAA;AAAA;AAAAD,OAAA,CAAAE,oBAAA;AAAA,IAAAC,SAAA,GAAAP,sBAAA,CAAAC,OAAA;AAAA,IAAAO,8BAAA,GAAAR,sBAAA,CAAAC,OAAA;AAEb,IAAAQ,MAAA,GAAAC,uBAAA,CAAAT,OAAA;AACA,IAAAU,WAAA,GAAAV,OAAA;AACA,IAAAW,QAAA,GAAAX,OAAA;AAEA,IAAAY,WAAA,GAAAb,sBAAA,CAAAC,OAAA;AACA,IAAAa,sBAAA,GAAAd,sBAAA,CAAAC,OAAA;AACA,IAAAc,uBAAA,GAAAf,sBAAA,CAAAC,OAAA;AACA,IAAAe,gBAAA,GAAAhB,sBAAA,CAAAC,OAAA;AACA,IAAAgB,OAAA,GAAAjB,sBAAA,CAAAC,OAAA;AAA+B,IAAAiB,WAAA,GAAAjB,OAAA;AAAA,MAAAkB,SAAA;AAAA,SAAAC,yBA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C,CAAC;EACrE,oBACE,IAAAjC,WAAA,CAAAwD,GAAA,EAAC7D,WAAA,CAAAc,OAAU,CAACgD,QAAQ;IAACtE,KAAK,EAAEyD,GAAI;IAAAc,QAAA,eAC9B,IAAA1D,WAAA,CAAAwD,GAAA,EAAC/D,WAAA,CAAAkE,qBAAqB,MAAAtE,SAAA,CAAAoB,OAAA,UAAApB,SAAA,CAAAoB,OAAA,MACVoB,KAAK;MAAEe;IAAG;MACpBgB,qBAAqB,EAAE,CAAC9B,KAAK,iBAAI,IAAA9B,WAAA,CAAAwD,GAAA,EAAC/D,WAAA,CAAAoE,uBAAuB;QAACjB,GAAG,EAAEA,GAAI;QAACkB,YAAY,EAAEjC,KAAK,CAACiC;MAAa,EAAI;MAAAJ,QAAA,EAExG7B,KAAK,CAAC6B;IAAQ;EACO,EACJ;AAE1B,CAAC;AAEM,MAAMtE,oBAA+C,GAAIyC,KAAK,IAAK;EACxEkC,eAAM,CAACC,kBAAkB,GAAGnC,KAAK,WAALA,KAAK,GAAI,CAAC,CAAC;EAEvC,oBACE,IAAA7B,WAAA,CAAAwD,GAAA,EAAClC,SAAS,MAAAjC,SAAA,CAAAoB,OAAA,MAAKoB,KAAK;IAAEoC,SAAS,EAAE,QAAS;IAAAP,QAAA,EACvC7B,KAAK,CAAC6B;EAAQ,GACL;AAEhB,CAAC;AAACxE,OAAA,CAAAE,oBAAA,GAAAA,oBAAA"}
package/common/hooks.js CHANGED
@@ -15,12 +15,15 @@ var _urls = require("../api/urls");
15
15
  */
16
16
 
17
17
  const useLogoutHostedLogin = () => {
18
+ const {
19
+ appName
20
+ } = (0, _reactHooks.useRootState)();
18
21
  const {
19
22
  logout
20
23
  } = (0, _reactHooks.useLoginActions)();
21
24
  return redirectUrl => {
22
- var _ContextHolder$getCon;
23
- const contextBaseUrl = (_ContextHolder$getCon = _restApi.ContextHolder.getContext()) == null ? void 0 : _ContextHolder$getCon.baseUrl;
25
+ var _ContextHolder$for$ge;
26
+ const contextBaseUrl = (_ContextHolder$for$ge = _restApi.ContextHolder.for(appName).getContext()) == null ? void 0 : _ContextHolder$for$ge.baseUrl;
24
27
  const baseUrl = typeof contextBaseUrl === 'function' ? contextBaseUrl('') : contextBaseUrl;
25
28
  const finalRedirectUrl = redirectUrl != null ? redirectUrl : window.location.href;
26
29
  const logoutRoute = (0, _urls.buildLogoutRoute)(finalRedirectUrl, baseUrl).asPath;
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","names":["_reactHooks","require","_restApi","_urls","useLogoutHostedLogin","logout","useLoginActions","redirectUrl","_ContextHolder$getCon","contextBaseUrl","ContextHolder","getContext","baseUrl","finalRedirectUrl","window","location","href","logoutRoute","buildLogoutRoute","asPath","exports"],"sources":["../../../../packages/nextjs/src/common/hooks.ts"],"sourcesContent":["import { useLoginActions } from '@frontegg/react-hooks';\nimport { ContextHolder } from '@frontegg/rest-api';\nimport { buildLogoutRoute } from '../api/urls';\n\n/**\n * Hook to logout client side for hosted login\n * @returns {Function} logout function to be used in the client side for hosted login\n * @param redirectUrl - The URL to redirect to after successful logout will be window.location.href by default.\n * @deprecated use `const { logout } = useLoginActions();`\n */\n\nexport const useLogoutHostedLogin = () => {\n const { logout } = useLoginActions();\n\n return (redirectUrl?: string) => {\n const contextBaseUrl = ContextHolder.getContext()?.baseUrl;\n const baseUrl = typeof contextBaseUrl === 'function' ? contextBaseUrl('') : contextBaseUrl;\n const finalRedirectUrl = redirectUrl ?? window.location.href;\n const logoutRoute = buildLogoutRoute(finalRedirectUrl, baseUrl).asPath;\n logout(() => {\n window.location.href = logoutRoute;\n });\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMG,oBAAoB,GAAGA,CAAA,KAAM;EACxC,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,2BAAe,GAAE;EAEpC,OAAQC,WAAoB,IAAK;IAAA,IAAAC,qBAAA;IAC/B,MAAMC,cAAc,IAAAD,qBAAA,GAAGE,sBAAa,CAACC,UAAU,EAAE,qBAA1BH,qBAAA,CAA4BI,OAAO;IAC1D,MAAMA,OAAO,GAAG,OAAOH,cAAc,KAAK,UAAU,GAAGA,cAAc,CAAC,EAAE,CAAC,GAAGA,cAAc;IAC1F,MAAMI,gBAAgB,GAAGN,WAAW,WAAXA,WAAW,GAAIO,MAAM,CAACC,QAAQ,CAACC,IAAI;IAC5D,MAAMC,WAAW,GAAG,IAAAC,sBAAgB,EAACL,gBAAgB,EAAED,OAAO,CAAC,CAACO,MAAM;IACtEd,MAAM,CAAC,MAAM;MACXS,MAAM,CAACC,QAAQ,CAACC,IAAI,GAAGC,WAAW;IACpC,CAAC,CAAC;EACJ,CAAC;AACH,CAAC;AAACG,OAAA,CAAAhB,oBAAA,GAAAA,oBAAA"}
1
+ {"version":3,"file":"hooks.js","names":["_reactHooks","require","_restApi","_urls","useLogoutHostedLogin","appName","useRootState","logout","useLoginActions","redirectUrl","_ContextHolder$for$ge","contextBaseUrl","ContextHolder","for","getContext","baseUrl","finalRedirectUrl","window","location","href","logoutRoute","buildLogoutRoute","asPath","exports"],"sources":["../../../../packages/nextjs/src/common/hooks.ts"],"sourcesContent":["import { useLoginActions, useRootState } from '@frontegg/react-hooks';\nimport { ContextHolder } from '@frontegg/rest-api';\nimport { buildLogoutRoute } from '../api/urls';\n\n/**\n * Hook to logout client side for hosted login\n * @returns {Function} logout function to be used in the client side for hosted login\n * @param redirectUrl - The URL to redirect to after successful logout will be window.location.href by default.\n * @deprecated use `const { logout } = useLoginActions();`\n */\n\nexport const useLogoutHostedLogin = () => {\n const { appName } = useRootState();\n const { logout } = useLoginActions();\n\n return (redirectUrl?: string) => {\n const contextBaseUrl = ContextHolder.for(appName).getContext()?.baseUrl;\n const baseUrl = typeof contextBaseUrl === 'function' ? contextBaseUrl('') : contextBaseUrl;\n const finalRedirectUrl = redirectUrl ?? window.location.href;\n const logoutRoute = buildLogoutRoute(finalRedirectUrl, baseUrl).asPath;\n logout(() => {\n window.location.href = logoutRoute;\n });\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMG,oBAAoB,GAAGA,CAAA,KAAM;EACxC,MAAM;IAAEC;EAAQ,CAAC,GAAG,IAAAC,wBAAY,GAAE;EAClC,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,2BAAe,GAAE;EAEpC,OAAQC,WAAoB,IAAK;IAAA,IAAAC,qBAAA;IAC/B,MAAMC,cAAc,IAAAD,qBAAA,GAAGE,sBAAa,CAACC,GAAG,CAACR,OAAO,CAAC,CAACS,UAAU,EAAE,qBAAvCJ,qBAAA,CAAyCK,OAAO;IACvE,MAAMA,OAAO,GAAG,OAAOJ,cAAc,KAAK,UAAU,GAAGA,cAAc,CAAC,EAAE,CAAC,GAAGA,cAAc;IAC1F,MAAMK,gBAAgB,GAAGP,WAAW,WAAXA,WAAW,GAAIQ,MAAM,CAACC,QAAQ,CAACC,IAAI;IAC5D,MAAMC,WAAW,GAAG,IAAAC,sBAAgB,EAACL,gBAAgB,EAAED,OAAO,CAAC,CAACO,MAAM;IACtEf,MAAM,CAAC,MAAM;MACXU,MAAM,CAACC,QAAQ,CAACC,IAAI,GAAGC,WAAW;IACpC,CAAC,CAAC;EACJ,CAAC;AACH,CAAC;AAACG,OAAA,CAAAnB,oBAAA,GAAAA,oBAAA"}
@@ -21,6 +21,17 @@ export declare enum EnvVariables {
21
21
  * - For Prod environment [visit](https://portal.frontegg.com/production/settings/general)
22
22
  */
23
23
  FRONTEGG_CLIENT_ID = "FRONTEGG_CLIENT_ID",
24
+ /**
25
+ * Your Frontegg application ID, get it by visit:
26
+ * - For Dev environment [visit](https://portal.frontegg.com/development/applications)
27
+ * - For Prod environment [visit](https://portal.frontegg.com/production/applications)
28
+ */
29
+ FRONTEGG_APP_ID = "FRONTEGG_APP_ID",
30
+ /**
31
+ * Rewrite the cookie name by the Frontegg application ID
32
+ * to support multiple Frontegg applications with same domain
33
+ */
34
+ FRONTEGG_REWRITE_COOKIE_BY_APP_ID = "FRONTEGG_REWRITE_COOKIE_BY_APP_ID",
24
35
  /**
25
36
  * Your Frontegg application's Client Secret, get it by visit:
26
37
  * - For Dev environment [visit](https://portal.frontegg.com/development/settings/general)
@@ -51,6 +62,16 @@ export declare enum EnvVariables {
51
62
  * value as session cookies for supporting getServerSideProps and ServerComponents
52
63
  */
53
64
  FRONTEGG_COOKIE_NAME = "FRONTEGG_COOKIE_NAME",
65
+ /**
66
+ * The stateless cookie domain for storing the encrypted JWT
67
+ * value as session cookies for supporting getServerSideProps and ServerComponents
68
+ */
69
+ FRONTEGG_COOKIE_DOMAIN = "FRONTEGG_COOKIE_DOMAIN",
70
+ /**
71
+ * The stateless cookie same site value for storing the encrypted JWT
72
+ * default is none, you can set it to 'lax' or 'strict' for more security
73
+ */
74
+ FRONTEGG_COOKIE_SAME_SITE = "FRONTEGG_COOKIE_SAME_SITE",
54
75
  /**
55
76
  * When `true`, the initial props will not refresh access token if it's valid.
56
77
  */
@@ -9,10 +9,14 @@ let EnvVariables = /*#__PURE__*/function (EnvVariables) {
9
9
  EnvVariables["FRONTEGG_BASE_URL"] = "FRONTEGG_BASE_URL";
10
10
  EnvVariables["FRONTEGG_TEST_URL"] = "FRONTEGG_TEST_URL";
11
11
  EnvVariables["FRONTEGG_CLIENT_ID"] = "FRONTEGG_CLIENT_ID";
12
+ EnvVariables["FRONTEGG_APP_ID"] = "FRONTEGG_APP_ID";
13
+ EnvVariables["FRONTEGG_REWRITE_COOKIE_BY_APP_ID"] = "FRONTEGG_REWRITE_COOKIE_BY_APP_ID";
12
14
  EnvVariables["FRONTEGG_CLIENT_SECRET"] = "FRONTEGG_CLIENT_SECRET";
13
15
  EnvVariables["FRONTEGG_ENCRYPTION_PASSWORD"] = "FRONTEGG_ENCRYPTION_PASSWORD";
14
16
  EnvVariables["FRONTEGG_JWT_PUBLIC_KEY"] = "FRONTEGG_JWT_PUBLIC_KEY";
15
17
  EnvVariables["FRONTEGG_COOKIE_NAME"] = "FRONTEGG_COOKIE_NAME";
18
+ EnvVariables["FRONTEGG_COOKIE_DOMAIN"] = "FRONTEGG_COOKIE_DOMAIN";
19
+ EnvVariables["FRONTEGG_COOKIE_SAME_SITE"] = "FRONTEGG_COOKIE_SAME_SITE";
16
20
  EnvVariables["DISABLE_INITIAL_PROPS_REFRESH_TOKEN"] = "DISABLE_INITIAL_PROPS_REFRESH_TOKEN";
17
21
  EnvVariables["FRONTEGG_SECURE_JWT_ENABLED"] = "FRONTEGG_SECURE_JWT_ENABLED";
18
22
  EnvVariables["FRONTEGG_HOSTED_LOGIN"] = "FRONTEGG_HOSTED_LOGIN";