@frontegg/nextjs 8.0.11-alpha.7463014450 → 8.0.11-alpha.7600753901

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## [8.0.11](https://github.com/frontegg/frontegg-nextjs/compare/v8.0.10...v8.0.11) (2024-1-21)
4
+
5
+
6
+ ### NextJS Wrapper 8.0.11:
7
+ - FR-14458 - fix build
8
+ - FR-14827 - allow alpha creation manually
9
+ - FR-14458 - Fixed error on middleware request since NextJs V14.0.2
10
+ - FR-14800 - remove app url end char if is /
11
+
3
12
  ## [8.0.10](https://github.com/frontegg/frontegg-nextjs/compare/v8.0.9...v8.0.10) (2023-12-31)
4
13
 
5
14
  - FR-14578 - Fixed custom login without tenant alias
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v8.0.11-alpha.7463014450
1
+ /** @license Frontegg v8.0.11-alpha.7600753901
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -8,7 +8,7 @@ var _FronteggProxy = require("./FronteggProxy");
8
8
  var _constants = require("./constants");
9
9
  var _helpers = require("./helpers");
10
10
  const middlewarePromise = (req, res) => new Promise(resolve => {
11
- var _req$url, _ref, _req$headers$xForwar, _req$headers, _req$headers2, _req$headers3;
11
+ var _req$url;
12
12
  const fronteggUrlPath = (0, _helpers.rewritePath)((_req$url = req.url) != null ? _req$url : '/', _constants.fronteggPathRewrite);
13
13
  const rewriteUrl = (0, _helpers.rewritePath)(fronteggUrlPath != null ? fronteggUrlPath : '/', _constants.fronteggSSOPathRewrite);
14
14
  req.url = rewriteUrl;
@@ -19,7 +19,6 @@ const middlewarePromise = (req, res) => new Promise(resolve => {
19
19
  if (process.env['FRONTEGG_TEST_URL'] && req.url == '/frontegg/middleware-test') {
20
20
  options.target = process.env['FRONTEGG_TEST_URL'];
21
21
  }
22
- req.headers['x-forwarded-port'] = ((_ref = (_req$headers$xForwar = (_req$headers = req.headers) == null ? void 0 : _req$headers['x-forwarded-port']) != null ? _req$headers$xForwar : (_req$headers2 = req.headers) == null ? void 0 : _req$headers2.port) != null ? _ref : ((_req$headers3 = req.headers) == null ? void 0 : _req$headers3.proto) == 'http') ? '3000' : '443';
23
22
  _FronteggProxy.FronteggProxy.web(req, res, options);
24
23
  });
25
24
 
@@ -1 +1 @@
1
- {"version":3,"file":"FronteggApiMiddleware.js","names":["_FronteggProxy","require","_constants","_helpers","middlewarePromise","req","res","Promise","resolve","_req$url","_ref","_req$headers$xForwar","_req$headers","_req$headers2","_req$headers3","fronteggUrlPath","rewritePath","url","fronteggPathRewrite","rewriteUrl","fronteggSSOPathRewrite","on","options","target","process","env","headers","port","proto","FronteggProxy","web","FronteggApiMiddleware"],"sources":["../../../../packages/nextjs/src/middleware/FronteggApiMiddleware.ts"],"sourcesContent":["import type { NextApiRequest, NextApiResponse } from 'next';\nimport { FronteggProxy } from './FronteggProxy';\nimport { fronteggSSOPathRewrite, fronteggPathRewrite } from './constants';\nimport { rewritePath } from './helpers';\n\nconst middlewarePromise = (req: NextApiRequest, res: NextApiResponse) =>\n new Promise<void>((resolve) => {\n const fronteggUrlPath = rewritePath(req.url ?? '/', fronteggPathRewrite);\n const rewriteUrl = rewritePath(fronteggUrlPath ?? '/', fronteggSSOPathRewrite);\n req.url = rewriteUrl;\n res.on('close', () => resolve());\n const options = {\n target: process.env['FRONTEGG_BASE_URL'],\n };\n if (process.env['FRONTEGG_TEST_URL'] && req.url == '/frontegg/middleware-test') {\n options.target = process.env['FRONTEGG_TEST_URL'];\n }\n\n req.headers['x-forwarded-port'] =\n req.headers?.['x-forwarded-port'] ?? req.headers?.port ?? req.headers?.proto == 'http' ? '3000' : '443';\n FronteggProxy.web(req, res, options);\n });\n\n/**\n * Next.js HTTP Proxy Middleware\n * @see https://nextjs.org/docs/api-routes/api-middlewares\n * @param {NextApiRequest} req - NextJS api request passed from api routing\n * @param {NextApiResponse} res - NextJS api response passed from api routing\n */\nexport async function FronteggApiMiddleware(req: NextApiRequest, res: NextApiResponse) {\n return await middlewarePromise(req, res);\n}\n"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,MAAMG,iBAAiB,GAAGA,CAACC,GAAmB,EAAEC,GAAoB,KAClE,IAAIC,OAAO,CAAQC,OAAO,IAAK;EAAA,IAAAC,QAAA,EAAAC,IAAA,EAAAC,oBAAA,EAAAC,YAAA,EAAAC,aAAA,EAAAC,aAAA;EAC7B,MAAMC,eAAe,GAAG,IAAAC,oBAAW,GAAAP,QAAA,GAACJ,GAAG,CAACY,GAAG,YAAAR,QAAA,GAAI,GAAG,EAAES,8BAAmB,CAAC;EACxE,MAAMC,UAAU,GAAG,IAAAH,oBAAW,EAACD,eAAe,WAAfA,eAAe,GAAI,GAAG,EAAEK,iCAAsB,CAAC;EAC9Ef,GAAG,CAACY,GAAG,GAAGE,UAAU;EACpBb,GAAG,CAACe,EAAE,CAAC,OAAO,EAAE,MAAMb,OAAO,EAAE,CAAC;EAChC,MAAMc,OAAO,GAAG;IACdC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAAC,mBAAmB;EACzC,CAAC;EACD,IAAID,OAAO,CAACC,GAAG,CAAC,mBAAmB,CAAC,IAAIpB,GAAG,CAACY,GAAG,IAAI,2BAA2B,EAAE;IAC9EK,OAAO,CAACC,MAAM,GAAGC,OAAO,CAACC,GAAG,CAAC,mBAAmB,CAAC;EACnD;EAEApB,GAAG,CAACqB,OAAO,CAAC,kBAAkB,CAAC,GAC7B,EAAAhB,IAAA,IAAAC,oBAAA,IAAAC,YAAA,GAAAP,GAAG,CAACqB,OAAO,qBAAXd,YAAA,CAAc,kBAAkB,CAAC,YAAAD,oBAAA,IAAAE,aAAA,GAAIR,GAAG,CAACqB,OAAO,qBAAXb,aAAA,CAAac,IAAI,YAAAjB,IAAA,GAAI,EAAAI,aAAA,GAAAT,GAAG,CAACqB,OAAO,qBAAXZ,aAAA,CAAac,KAAK,KAAI,MAAM,IAAG,MAAM,GAAG,KAAK;EACzGC,4BAAa,CAACC,GAAG,CAACzB,GAAG,EAAEC,GAAG,EAAEgB,OAAO,CAAC;AACtC,CAAC,CAAC;;AAEJ;AACA;AACA;AACA;AACA;AACA;AACO,eAAeS,qBAAqBA,CAAC1B,GAAmB,EAAEC,GAAoB,EAAE;EACrF,OAAO,MAAMF,iBAAiB,CAACC,GAAG,EAAEC,GAAG,CAAC;AAC1C"}
1
+ {"version":3,"file":"FronteggApiMiddleware.js","names":["_FronteggProxy","require","_constants","_helpers","middlewarePromise","req","res","Promise","resolve","_req$url","fronteggUrlPath","rewritePath","url","fronteggPathRewrite","rewriteUrl","fronteggSSOPathRewrite","on","options","target","process","env","FronteggProxy","web","FronteggApiMiddleware"],"sources":["../../../../packages/nextjs/src/middleware/FronteggApiMiddleware.ts"],"sourcesContent":["import type { NextApiRequest, NextApiResponse } from 'next';\nimport { FronteggProxy } from './FronteggProxy';\nimport { fronteggSSOPathRewrite, fronteggPathRewrite } from './constants';\nimport { rewritePath } from './helpers';\n\nconst middlewarePromise = (req: NextApiRequest, res: NextApiResponse) =>\n new Promise<void>((resolve) => {\n const fronteggUrlPath = rewritePath(req.url ?? '/', fronteggPathRewrite);\n const rewriteUrl = rewritePath(fronteggUrlPath ?? '/', fronteggSSOPathRewrite);\n req.url = rewriteUrl;\n res.on('close', () => resolve());\n const options = {\n target: process.env['FRONTEGG_BASE_URL'],\n };\n if (process.env['FRONTEGG_TEST_URL'] && req.url == '/frontegg/middleware-test') {\n options.target = process.env['FRONTEGG_TEST_URL'];\n }\n\n FronteggProxy.web(req, res, options);\n });\n\n/**\n * Next.js HTTP Proxy Middleware\n * @see https://nextjs.org/docs/api-routes/api-middlewares\n * @param {NextApiRequest} req - NextJS api request passed from api routing\n * @param {NextApiResponse} res - NextJS api response passed from api routing\n */\nexport async function FronteggApiMiddleware(req: NextApiRequest, res: NextApiResponse) {\n return await middlewarePromise(req, res);\n}\n"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,MAAMG,iBAAiB,GAAGA,CAACC,GAAmB,EAAEC,GAAoB,KAClE,IAAIC,OAAO,CAAQC,OAAO,IAAK;EAAA,IAAAC,QAAA;EAC7B,MAAMC,eAAe,GAAG,IAAAC,oBAAW,GAAAF,QAAA,GAACJ,GAAG,CAACO,GAAG,YAAAH,QAAA,GAAI,GAAG,EAAEI,8BAAmB,CAAC;EACxE,MAAMC,UAAU,GAAG,IAAAH,oBAAW,EAACD,eAAe,WAAfA,eAAe,GAAI,GAAG,EAAEK,iCAAsB,CAAC;EAC9EV,GAAG,CAACO,GAAG,GAAGE,UAAU;EACpBR,GAAG,CAACU,EAAE,CAAC,OAAO,EAAE,MAAMR,OAAO,EAAE,CAAC;EAChC,MAAMS,OAAO,GAAG;IACdC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAAC,mBAAmB;EACzC,CAAC;EACD,IAAID,OAAO,CAACC,GAAG,CAAC,mBAAmB,CAAC,IAAIf,GAAG,CAACO,GAAG,IAAI,2BAA2B,EAAE;IAC9EK,OAAO,CAACC,MAAM,GAAGC,OAAO,CAACC,GAAG,CAAC,mBAAmB,CAAC;EACnD;EAEAC,4BAAa,CAACC,GAAG,CAACjB,GAAG,EAAEC,GAAG,EAAEW,OAAO,CAAC;AACtC,CAAC,CAAC;;AAEJ;AACA;AACA;AACA;AACA;AACA;AACO,eAAeM,qBAAqBA,CAAClB,GAAmB,EAAEC,GAAoB,EAAE;EACrF,OAAO,MAAMF,iBAAiB,CAACC,GAAG,EAAEC,GAAG,CAAC;AAC1C"}
@@ -14,7 +14,13 @@ var _ProxyResponseCallback = _interopRequireDefault(require("./ProxyResponseCall
14
14
  const FronteggProxy = (0, _httpProxy.createProxyServer)({
15
15
  target: process.env['FRONTEGG_BASE_URL'],
16
16
  changeOrigin: true,
17
- selfHandleResponse: true
17
+ selfHandleResponse: true,
18
+ /**
19
+ * We set xfwd to true to avoid next-js buggy implementation of x-forwarded-* headers in version 14.0.2
20
+ * They set the x-forwarded-port header to be 'undefined' in production environment - https://github.com/vercel/next.js/issues/58295
21
+ * This causes our proxy middleware to fail on every request
22
+ */
23
+ xfwd: true
18
24
  });
19
25
 
20
26
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"FronteggProxy.js","names":["_httpProxy","require","_ProxyRequestCallback","_interopRequireDefault","_ProxyResponseCallback","FronteggProxy","createProxyServer","target","process","env","changeOrigin","selfHandleResponse","exports","on","ProxyRequestCallback","ProxyResponseCallback"],"sources":["../../../../packages/nextjs/src/middleware/FronteggProxy.ts"],"sourcesContent":["import { createProxyServer } from 'http-proxy';\nimport ProxyRequestCallback from './ProxyRequestCallback';\nimport ProxyResponseCallback from './ProxyResponseCallback';\n\n/**\n * @see https://www.npmjs.com/package/http-proxy\n */\nexport const FronteggProxy = createProxyServer({\n target: process.env['FRONTEGG_BASE_URL'],\n changeOrigin: true,\n selfHandleResponse: true,\n});\n\n/**\n * Set proxy request callback handler\n */\n// @ts-ignore\nFronteggProxy.on('proxyReq', ProxyRequestCallback);\n/**\n * Set proxy response callback handler\n */\n// @ts-ignore\nFronteggProxy.on('proxyRes', ProxyResponseCallback);\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA;AACA;AACA;AACO,MAAMI,aAAa,GAAG,IAAAC,4BAAiB,EAAC;EAC7CC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAAC,mBAAmB,CAAC;EACxCC,YAAY,EAAE,IAAI;EAClBC,kBAAkB,EAAE;AACtB,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AAAAC,OAAA,CAAAP,aAAA,GAAAA,aAAA;AACAA,aAAa,CAACQ,EAAE,CAAC,UAAU,EAAEC,6BAAoB,CAAC;AAClD;AACA;AACA;AACA;AACAT,aAAa,CAACQ,EAAE,CAAC,UAAU,EAAEE,8BAAqB,CAAC"}
1
+ {"version":3,"file":"FronteggProxy.js","names":["_httpProxy","require","_ProxyRequestCallback","_interopRequireDefault","_ProxyResponseCallback","FronteggProxy","createProxyServer","target","process","env","changeOrigin","selfHandleResponse","xfwd","exports","on","ProxyRequestCallback","ProxyResponseCallback"],"sources":["../../../../packages/nextjs/src/middleware/FronteggProxy.ts"],"sourcesContent":["import { createProxyServer } from 'http-proxy';\nimport ProxyRequestCallback from './ProxyRequestCallback';\nimport ProxyResponseCallback from './ProxyResponseCallback';\n\n/**\n * @see https://www.npmjs.com/package/http-proxy\n */\nexport const FronteggProxy = createProxyServer({\n target: process.env['FRONTEGG_BASE_URL'],\n changeOrigin: true,\n selfHandleResponse: true,\n /**\n * We set xfwd to true to avoid next-js buggy implementation of x-forwarded-* headers in version 14.0.2\n * They set the x-forwarded-port header to be 'undefined' in production environment - https://github.com/vercel/next.js/issues/58295\n * This causes our proxy middleware to fail on every request\n */\n xfwd: true,\n});\n\n/**\n * Set proxy request callback handler\n */\n// @ts-ignore\nFronteggProxy.on('proxyReq', ProxyRequestCallback);\n/**\n * Set proxy response callback handler\n */\n// @ts-ignore\nFronteggProxy.on('proxyRes', ProxyResponseCallback);\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA;AACA;AACA;AACO,MAAMI,aAAa,GAAG,IAAAC,4BAAiB,EAAC;EAC7CC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAAC,mBAAmB,CAAC;EACxCC,YAAY,EAAE,IAAI;EAClBC,kBAAkB,EAAE,IAAI;EACxB;AACF;AACA;AACA;AACA;EACEC,IAAI,EAAE;AACR,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AAAAC,OAAA,CAAAR,aAAA,GAAAA,aAAA;AACAA,aAAa,CAACS,EAAE,CAAC,UAAU,EAAEC,6BAAoB,CAAC;AAClD;AACA;AACA;AACA;AACAV,aAAa,CAACS,EAAE,CAAC,UAAU,EAAEE,8BAAqB,CAAC"}
@@ -10,8 +10,6 @@ var _sdkVersion = _interopRequireDefault(require("../sdkVersion"));
10
10
  var _config = _interopRequireDefault(require("../config"));
11
11
  var _cookies = _interopRequireDefault(require("../utils/cookies"));
12
12
  var _fronteggLogger = _interopRequireDefault(require("../utils/fronteggLogger"));
13
- const HEADERS_TO_KEEP = ['x-forwarded-for', 'x-original-forwarded-for', 'cf-connecting-ip'];
14
- const HEADERS_TO_REMOVE = ['x-forwarded-port', 'x-invoke-path', 'x-invoke-query', 'x-middleware-invoke', 'x-middleware-next', 'transfer-encoding', 'cache-control'];
15
13
  const logger = _fronteggLogger.default.child({
16
14
  tag: 'FronteggApiMiddleware.ProxyRequestCallback'
17
15
  });
@@ -42,14 +40,19 @@ const ProxyRequestCallback = (proxyReq, req) => {
42
40
  proxyReq.setHeader('x-frontegg-framework', (_req$headers$xFronte = req.headers['x-frontegg-framework']) != null ? _req$headers$xFronte : `next@${_package.default.version}`);
43
41
  proxyReq.setHeader('x-frontegg-sdk', (_req$headers$xFronte2 = req.headers['x-frontegg-sdk']) != null ? _req$headers$xFronte2 : `@frontegg/nextjs@${_sdkVersion.default.version}`);
44
42
  proxyReq.setHeader('x-frontegg-middleware', 'true');
45
- HEADERS_TO_KEEP.forEach(header => {
46
- const headerValue = req.headers[header];
47
- console.log(`headerValue for ${header} is `, headerValue);
48
- if (headerValue && headerValue != 'undefined') {
49
- proxyReq.setHeader(header, headerValue);
50
- }
51
- });
52
- HEADERS_TO_REMOVE.map(header => proxyReq.removeHeader(header));
43
+ const xForwardedFor = req.headers['x-forwarded-for'];
44
+ const xOriginalForwardedFor = req.headers['x-original-forwarded-for'];
45
+ const cfConnectionIp = req.headers['cf-connecting-ip'];
46
+ if (xForwardedFor) {
47
+ proxyReq.setHeader('x-forwarded-for', xForwardedFor);
48
+ }
49
+ if (xOriginalForwardedFor) {
50
+ proxyReq.setHeader('x-original-forwarded-for', xOriginalForwardedFor);
51
+ }
52
+ if (cfConnectionIp) {
53
+ proxyReq.setHeader('cf-connecting-ip', cfConnectionIp);
54
+ }
55
+ ['x-invoke-path', 'x-invoke-query', 'x-middleware-invoke', 'x-middleware-next', 'transfer-encoding', 'cache-control'].map(header => proxyReq.removeHeader(header));
53
56
  logger.debug(`${req.url} | check if request has body`);
54
57
  if (req.method !== 'GET' && req.body) {
55
58
  logger.debug(`${req.url} | writing request body to proxyReq`);
@@ -1 +1 @@
1
- {"version":3,"file":"ProxyRequestCallback.js","names":["_package","_interopRequireDefault","require","_sdkVersion","_config","_cookies","_fronteggLogger","HEADERS_TO_KEEP","HEADERS_TO_REMOVE","logger","fronteggLogger","child","tag","ProxyRequestCallback","proxyReq","req","_req$headers$xFronte","_req$headers$xFronte2","info","url","headers","debug","allCookies","CookieManager","parseCookieHeader","fronteggCookiesNames","Object","keys","filter","cookieName","startsWith","config","join","forEach","setHeader","NextJsPkg","version","sdkVersion","header","headerValue","console","log","map","removeHeader","method","body","bodyData","JSON","stringify","Buffer","byteLength","write","e","error","_default","exports","default"],"sources":["../../../../packages/nextjs/src/middleware/ProxyRequestCallback.ts"],"sourcesContent":["import NextJsPkg from 'next/package.json';\nimport { ProxyReqCallback } from 'http-proxy';\nimport { ClientRequest } from 'http';\nimport { NextApiRequest } from 'next';\nimport sdkVersion from '../sdkVersion';\nimport config from '../config';\nimport CookieManager from '../utils/cookies';\nimport fronteggLogger from '../utils/fronteggLogger';\n\nconst HEADERS_TO_KEEP = ['x-forwarded-for', 'x-original-forwarded-for', 'cf-connecting-ip'];\nconst HEADERS_TO_REMOVE = [\n 'x-forwarded-port',\n 'x-invoke-path',\n 'x-invoke-query',\n 'x-middleware-invoke',\n 'x-middleware-next',\n 'transfer-encoding',\n 'cache-control',\n];\nconst logger = fronteggLogger.child({ tag: 'FronteggApiMiddleware.ProxyRequestCallback' });\n/**\n * Proxy request callback fired on before each request to Frontegg services,\n * to transport frontegg cookies.\n *\n * @param {ClientRequest} proxyReq - Proxy request to be sent\n * @param {NextApiRequest} req - Next.js incoming request\n */\nconst ProxyRequestCallback: ProxyReqCallback<ClientRequest, NextApiRequest> = (proxyReq, req) => {\n try {\n logger.info(`${req.url} | Going to proxy request`);\n logger.info('The original req headers are', { headers: req.headers });\n logger.debug(`${req.url} | parsing request cookies`);\n const allCookies = CookieManager.parseCookieHeader(req);\n logger.debug(`${req.url} | found ${allCookies} cookies`);\n const fronteggCookiesNames = Object.keys(allCookies).filter((cookieName) => {\n return cookieName.startsWith('fe_') && !cookieName.startsWith(config.cookieName);\n });\n\n logger.debug(`${req.url} | proxy FronteggCookies (${fronteggCookiesNames.join(', ')})`);\n fronteggCookiesNames.forEach((cookieName: string) => {\n proxyReq.setHeader(cookieName, allCookies[cookieName]);\n });\n\n proxyReq.setHeader('x-frontegg-framework', req.headers['x-frontegg-framework'] ?? `next@${NextJsPkg.version}`);\n proxyReq.setHeader('x-frontegg-sdk', req.headers['x-frontegg-sdk'] ?? `@frontegg/nextjs@${sdkVersion.version}`);\n proxyReq.setHeader('x-frontegg-middleware', 'true');\n\n HEADERS_TO_KEEP.forEach((header) => {\n const headerValue = req.headers[header];\n console.log(`headerValue for ${header} is `, headerValue);\n if (headerValue && headerValue != 'undefined') {\n proxyReq.setHeader(header, headerValue);\n }\n });\n HEADERS_TO_REMOVE.map((header) => proxyReq.removeHeader(header));\n\n logger.debug(`${req.url} | check if request has body`);\n if (req.method !== 'GET' && req.body) {\n logger.debug(`${req.url} | writing request body to proxyReq`);\n const bodyData = JSON.stringify(req.body);\n // in case if content-type is application/x-www-form-urlencoded -> we need to change to application/json\n proxyReq.setHeader('Content-Type', 'application/json');\n proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));\n // stream the content\n proxyReq.write(bodyData);\n }\n } catch (e) {\n logger.error(`${req.url} | Failed to proxy request`, e);\n }\n};\n\nexport default ProxyRequestCallback;\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,eAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEA,MAAMK,eAAe,GAAG,CAAC,iBAAiB,EAAE,0BAA0B,EAAE,kBAAkB,CAAC;AAC3F,MAAMC,iBAAiB,GAAG,CACxB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,CAChB;AACD,MAAMC,MAAM,GAAGC,uBAAc,CAACC,KAAK,CAAC;EAAEC,GAAG,EAAE;AAA6C,CAAC,CAAC;AAC1F;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,oBAAqE,GAAGA,CAACC,QAAQ,EAAEC,GAAG,KAAK;EAC/F,IAAI;IAAA,IAAAC,oBAAA,EAAAC,qBAAA;IACFR,MAAM,CAACS,IAAI,CAAE,GAAEH,GAAG,CAACI,GAAI,2BAA0B,CAAC;IAClDV,MAAM,CAACS,IAAI,CAAC,8BAA8B,EAAE;MAAEE,OAAO,EAAEL,GAAG,CAACK;IAAQ,CAAC,CAAC;IACrEX,MAAM,CAACY,KAAK,CAAE,GAAEN,GAAG,CAACI,GAAI,4BAA2B,CAAC;IACpD,MAAMG,UAAU,GAAGC,gBAAa,CAACC,iBAAiB,CAACT,GAAG,CAAC;IACvDN,MAAM,CAACY,KAAK,CAAE,GAAEN,GAAG,CAACI,GAAI,YAAWG,UAAW,UAAS,CAAC;IACxD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AAEJ,MAAM,IAAKxB,QAAQ,CAAC6B,YAAY,CAACL,MAAM,CAAC,CAAC;IAEhE7B,MAAM,CAACY,KAAK,CAAE,GAAEN,GAAG,CAACI,GAAI,8BAA6B,CAAC;IACtD,IAAIJ,GAAG,CAAC6B,MAAM,KAAK,KAAK,IAAI7B,GAAG,CAAC8B,IAAI,EAAE;MACpCpC,MAAM,CAACY,KAAK,CAAE,GAAEN,GAAG,CAACI,GAAI,qCAAoC,CAAC;MAC7D,MAAM2B,QAAQ,GAAGC,IAAI,CAACC,SAAS,CAACjC,GAAG,CAAC8B,IAAI,CAAC;MACzC;MACA/B,QAAQ,CAACoB,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC;MACtDpB,QAAQ,CAACoB,SAAS,CAAC,gBAAgB,EAAEe,MAAM,CAACC,UAAU,CAACJ,QAAQ,CAAC,CAAC;MACjE;MACAhC,QAAQ,CAACqC,KAAK,CAACL,QAAQ,CAAC;IAC1B;EACF,CAAC,CAAC,OAAOM,CAAC,EAAE;IACV3C,MAAM,CAAC4C,KAAK,CAAE,GAAEtC,GAAG,CAACI,GAAI,4BAA2B,EAAEiC,CAAC,CAAC;EACzD;AACF,CAAC;AAAC,IAAAE,QAAA,GAEazC,oBAAoB;AAAA0C,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
1
+ {"version":3,"file":"ProxyRequestCallback.js","names":["_package","_interopRequireDefault","require","_sdkVersion","_config","_cookies","_fronteggLogger","logger","fronteggLogger","child","tag","ProxyRequestCallback","proxyReq","req","_req$headers$xFronte","_req$headers$xFronte2","info","url","headers","debug","allCookies","CookieManager","parseCookieHeader","fronteggCookiesNames","Object","keys","filter","cookieName","startsWith","config","join","forEach","setHeader","NextJsPkg","version","sdkVersion","xForwardedFor","xOriginalForwardedFor","cfConnectionIp","map","header","removeHeader","method","body","bodyData","JSON","stringify","Buffer","byteLength","write","e","error","_default","exports","default"],"sources":["../../../../packages/nextjs/src/middleware/ProxyRequestCallback.ts"],"sourcesContent":["import NextJsPkg from 'next/package.json';\nimport { ProxyReqCallback } from 'http-proxy';\nimport { ClientRequest } from 'http';\nimport { NextApiRequest } from 'next';\nimport sdkVersion from '../sdkVersion';\nimport config from '../config';\nimport CookieManager from '../utils/cookies';\nimport fronteggLogger from '../utils/fronteggLogger';\n\nconst logger = fronteggLogger.child({ tag: 'FronteggApiMiddleware.ProxyRequestCallback' });\n/**\n * Proxy request callback fired on before each request to Frontegg services,\n * to transport frontegg cookies.\n *\n * @param {ClientRequest} proxyReq - Proxy request to be sent\n * @param {NextApiRequest} req - Next.js incoming request\n */\nconst ProxyRequestCallback: ProxyReqCallback<ClientRequest, NextApiRequest> = (proxyReq, req) => {\n try {\n logger.info(`${req.url} | Going to proxy request`);\n logger.info('The original req headers are', { headers: req.headers });\n logger.debug(`${req.url} | parsing request cookies`);\n const allCookies = CookieManager.parseCookieHeader(req);\n logger.debug(`${req.url} | found ${allCookies} cookies`);\n const fronteggCookiesNames = Object.keys(allCookies).filter((cookieName) => {\n return cookieName.startsWith('fe_') && !cookieName.startsWith(config.cookieName);\n });\n\n logger.debug(`${req.url} | proxy FronteggCookies (${fronteggCookiesNames.join(', ')})`);\n fronteggCookiesNames.forEach((cookieName: string) => {\n proxyReq.setHeader(cookieName, allCookies[cookieName]);\n });\n\n proxyReq.setHeader('x-frontegg-framework', req.headers['x-frontegg-framework'] ?? `next@${NextJsPkg.version}`);\n proxyReq.setHeader('x-frontegg-sdk', req.headers['x-frontegg-sdk'] ?? `@frontegg/nextjs@${sdkVersion.version}`);\n proxyReq.setHeader('x-frontegg-middleware', 'true');\n\n const xForwardedFor = req.headers['x-forwarded-for'];\n const xOriginalForwardedFor = req.headers['x-original-forwarded-for'];\n const cfConnectionIp = req.headers['cf-connecting-ip'];\n\n if (xForwardedFor) {\n proxyReq.setHeader('x-forwarded-for', xForwardedFor);\n }\n if (xOriginalForwardedFor) {\n proxyReq.setHeader('x-original-forwarded-for', xOriginalForwardedFor);\n }\n if (cfConnectionIp) {\n proxyReq.setHeader('cf-connecting-ip', cfConnectionIp);\n }\n\n [\n 'x-invoke-path',\n 'x-invoke-query',\n 'x-middleware-invoke',\n 'x-middleware-next',\n 'transfer-encoding',\n 'cache-control',\n ].map((header) => proxyReq.removeHeader(header));\n\n logger.debug(`${req.url} | check if request has body`);\n if (req.method !== 'GET' && req.body) {\n logger.debug(`${req.url} | writing request body to proxyReq`);\n const bodyData = JSON.stringify(req.body);\n // in case if content-type is application/x-www-form-urlencoded -> we need to change to application/json\n proxyReq.setHeader('Content-Type', 'application/json');\n proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));\n // stream the content\n proxyReq.write(bodyData);\n }\n } catch (e) {\n logger.error(`${req.url} | Failed to proxy request`, e);\n }\n};\n\nexport default ProxyRequestCallback;\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,eAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEA,MAAMK,MAAM,GAAGC,uBAAc,CAACC,KAAK,CAAC;EAAEC,GAAG,EAAE;AAA6C,CAAC,CAAC;AAC1F;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,oBAAqE,GAAGA,CAACC,QAAQ,EAAEC,GAAG,KAAK;EAC/F,IAAI;IAAA,IAAAC,oBAAA,EAAAC,qBAAA;IACFR,MAAM,CAACS,IAAI,CAAE,GAAEH,GAAG,CAACI,GAAI,2BAA0B,CAAC;IAClDV,MAAM,CAACS,IAAI,CAAC,8BAA8B,EAAE;MAAEE,OAAO,EAAEL,GAAG,CAACK;IAAQ,CAAC,CAAC;IACrEX,MAAM,CAACY,KAAK,CAAE,GAAEN,GAAG,CAACI,GAAI,4BAA2B,CAAC;IACpD,MAAMG,UAAU,GAAGC,g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) => {
84
84
  }
85
85
  }
86
86
  Object.keys(proxyRes.headers).filter(header => header !== 'cookie').forEach(header => {
87
- const headerValue = proxyRes.headers[header];
88
- console.log(`headerValue for ${header} is `, headerValue);
89
- if (headerValue && headerValue != 'undefined') {
90
- res.setHeader(header, `${headerValue}`);
91
- }
87
+ res.setHeader(header, `${proxyRes.headers[header]}`);
92
88
  });
93
89
  res.setHeader('set-cookie', cookies);
94
90
  res.status(statusCode).end(bodyStr);
@@ -97,11 +93,7 @@ const ProxyResponseCallback = (proxyRes, req, res) => {
97
93
  logger.error(`Middleware request failed statusCode: ${statusCode} for url: ${url}`);
98
94
  }
99
95
  Object.keys(proxyRes.headers).filter(header => header !== 'cookie').forEach(header => {
100
- const headerValue = proxyRes.headers[header];
101
- console.log(`headerValue for ${header} is `, headerValue);
102
- if (headerValue && headerValue != 'undefined') {
103
- res.setHeader(header, `${headerValue}`);
104
- }
96
+ res.setHeader(header, `${proxyRes.headers[header]}`);
105
97
  });
106
98
  res.status(statusCode).end(bodyStr);
107
99
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ProxyResponseCallback.js","names":["_config","_interopRequireDefault","require","_cookies","_common","_helpers","_fronteggLogger","_helpers2","logger","fronteggLogger","child","tag","ProxyResponseCallback","proxyRes","req","res","buffer","Buffer","totalLength","isSecured","URL","config","appUrl","protocol","on","chunk","length","concat","_proxyRes$statusCode","url","statusCode","isSuccess","bodyStr","toString","isLogout","isFronteggLogoutUrl","CookieManager","removeCookies","cookieDomain","status","end","_CookieManager$modify","cookies","modifySetCookie","headers","body","JSON","parse","accessToken","access_token","session","decodedJwt","createSessionFromAccessToken","sessionCookie","create","value","expires","Date","exp","secure","push","e","isSSOPostRequest","error","Object","keys","filter","header","forEach","headerValue","console","log","setHeader","_default","exports","default"],"sources":["../../../../packages/nextjs/src/middleware/ProxyResponseCallback.ts"],"sourcesContent":["import { ProxyResCallback } from 'http-proxy';\nimport { IncomingMessage } from 'http';\nimport { NextApiResponse } from 'next';\nimport config from '../config';\nimport CookieManager from '../utils/cookies';\nimport { createSessionFromAccessToken } from '../common';\nimport { isFronteggLogoutUrl } from './helpers';\nimport fronteggLogger from '../utils/fronteggLogger';\nimport { isSSOPostRequest } from '../utils/refreshAccessToken/helpers';\n\nconst logger = fronteggLogger.child({ tag: 'FronteggApiMiddleware.ProxyResponseCallback' });\n/**\n * Proxy response callback fired on after each response from Frontegg services,\n * to transport frontegg modify cookies and generating encrypted JWT session cookie.\n *\n * @param {IncomingMessage} proxyRes - Proxy response from Frontegg services\n * @param {NextApiRequest} req - Next.js request sent from client-side\n * @param {NextApiResponse} res - Next.js response to send to client-side\n */\nconst ProxyResponseCallback: ProxyResCallback<IncomingMessage, NextApiResponse> = (proxyRes, req, res) => {\n let buffer = new Buffer('');\n let totalLength: number = 0;\n const isSecured = new URL(config.appUrl).protocol === 'https:';\n\n proxyRes.on('data', (chunk: Buffer) => {\n totalLength += chunk.length;\n buffer = Buffer.concat([buffer, chunk], totalLength);\n });\n proxyRes.on('end', async () => {\n try {\n const url = req.url!;\n const statusCode = proxyRes.statusCode ?? 500;\n const isSuccess = statusCode >= 200 && statusCode < 400;\n const bodyStr = buffer.toString('utf-8');\n const isLogout = isFronteggLogoutUrl(url);\n\n if (isLogout) {\n CookieManager.removeCookies({\n isSecured,\n cookieDomain: config.cookieDomain,\n res,\n req,\n });\n res.status(statusCode).end(bodyStr);\n return;\n }\n\n if (isSuccess) {\n const cookies = CookieManager.modifySetCookie(proxyRes.headers['set-cookie'], isSecured) ?? [];\n\n try {\n if (bodyStr && bodyStr.length > 0) {\n const body = JSON.parse(bodyStr);\n if (body.accessToken || body.access_token) {\n const [session, decodedJwt] = await createSessionFromAccessToken(body);\n if (session) {\n const sessionCookie = CookieManager.create({\n value: session,\n expires: new Date(decodedJwt.exp * 1000),\n secure: isSecured,\n req,\n });\n cookies.push(...sessionCookie);\n }\n }\n }\n } catch (e) {\n /** ignore api call if:\n * - Does not have accessToken / access_token\n * - Not json response\n */\n if (statusCode === 302 && isSSOPostRequest(url)) {\n /**\n * Ignore saml/oidc postLogin response with redirect\n */\n } else {\n logger.error('failed to create session', e, {\n url,\n statusCode,\n });\n }\n }\n Object.keys(proxyRes.headers)\n .filter((header) => header !== 'cookie')\n .forEach((header) => {\n const headerValue = proxyRes.headers[header];\n console.log(`headerValue for ${header} is `, headerValue);\n if (headerValue && headerValue != 'undefined') {\n res.setHeader(header, `${headerValue}`);\n }\n });\n res.setHeader('set-cookie', cookies);\n res.status(statusCode).end(bodyStr);\n } else {\n if (statusCode >= 400 && statusCode !== 404) {\n logger.error(`Middleware request failed statusCode: ${statusCode} for url: ${url}`);\n }\n Object.keys(proxyRes.headers)\n .filter((header) => header !== 'cookie')\n .forEach((header) => {\n const headerValue = proxyRes.headers[header];\n console.log(`headerValue for ${header} is `, headerValue);\n if (headerValue && headerValue != 'undefined') {\n res.setHeader(header, `${headerValue}`);\n }\n });\n res.status(statusCode).end(bodyStr);\n }\n } catch (e: any) {\n logger.error('proxy failed to send request', e);\n res.status(500).end('Internal Server Error');\n }\n });\n};\n\nexport default ProxyResponseCallback;\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAEA,MAAMM,MAAM,GAAGC,uBAAc,CAACC,KAAK,CAAC;EAAEC,GAAG,EAAE;AAA8C,CAAC,CAAC;AAC3F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,qBAAyE,GAAGA,CAACC,QAAQ,EAAEC,GAAG,EAAEC,GAAG,KAAK;EACxG,IAAIC,MAAM,GAAG,IAAIC,MAAM,CAAC,EAAE,CAAC;EAC3B,IAAIC,WAAmB,GAAG,CAAC;EAC3B,MA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tD,GAAG,CAACyD,SAAS,CAAC,YAAY,EAAE9B,OAAO,CAAC;QACpC3B,GAAG,CAACwB,MAAM,CAACT,UAAU,CAAC,CAACU,GAAG,CAACR,OAAO,CAAC;MACrC,CAAC,MAAM;QACL,IAAIF,UAAU,IAAI,GAAG,IAAIA,UAAU,KAAK,GAAG,EAAE;UAC3CtB,MAAM,CAACuD,KAAK,CAAE,yCAAwCjC,UAAW,aAAYD,GAAI,EAAC,CAAC;QACrF;QACAmC,MAAM,CAACC,IAAI,CAACpD,QAAQ,CAAC+B,OAAO,CAAC,CAC1BsB,MAAM,CAAEC,MAAM,IAAKA,MAAM,KAAK,QAAQ,CAAC,CACvCC,OAAO,CAAED,MAAM,IAAK;UACnB,MAAME,WAAW,GAAGxD,QAAQ,CAAC+B,OAAO,CAACuB,MAAM,CAAC;UAC5CG,OAAO,CAACC,GAAG,CAAE,mBAAkBJ,MAAO,MAAK,EAAEE,WAAW,CAAC;UACzD,IAAIA,WAAW,IAAIA,WAAW,IAAI,WAAW,EAAE;YAC7CtD,GAAG,CAACyD,SAAS,CAACL,MAAM,EAAG,GAAEE,WAAY,EAAC,CAAC;UACzC;QACF,CAAC,CAAC;QACJtD,GAAG,CAACwB,MAAM,CAACT,UAAU,CAAC,CAACU,GAAG,CAACR,OAAO,CAAC;MACrC;IACF,CAAC,CAAC,OAAO6B,CAAM,EAAE;MACfrD,MAAM,CAACuD,KAAK,CAAC,8BAA8B,EAAEF,CAAC,CAAC;MAC/C9C,GAAG,CAACwB,MAAM,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,uBAAuB,CAAC;IAC9C;EACF,CAAC,CAAC;AACJ,CAAC;AAAC,IAAAiC,QAAA,GAEa7D,qBAAqB;AAAA8D,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
1
+ {"version":3,"file":"ProxyResponseCallback.js","names":["_config","_interopRequireDefault","require","_cookies","_common","_helpers","_fronteggLogger","_helpers2","logger","fronteggLogger","child","tag","ProxyResponseCallback","proxyRes","req","res","buffer","Buffer","totalLength","isSecured","URL","config","appUrl","protocol","on","chunk","length","concat","_proxyRes$statusCode","url","statusCode","isSuccess","bodyStr","toString","isLogout","isFronteggLogoutUrl","CookieManager","removeCookies","cookieDomain","status","end","_CookieManager$modify","cookies","modifySetCookie","headers","body","JSON","parse","accessToken","access_token","session","decodedJwt","createSessionFromAccessToken","sessionCookie","create","value","expires","Date","exp","secure","push","e","isSSOPostRequest","error","Object","keys","filter","header","forEach","setHeader","_default","exports","default"],"sources":["../../../../packages/nextjs/src/middleware/ProxyResponseCallback.ts"],"sourcesContent":["import { ProxyResCallback } from 'http-proxy';\nimport { IncomingMessage } from 'http';\nimport { NextApiResponse } from 'next';\nimport config from '../config';\nimport CookieManager from '../utils/cookies';\nimport { createSessionFromAccessToken } from '../common';\nimport { isFronteggLogoutUrl } from './helpers';\nimport fronteggLogger from '../utils/fronteggLogger';\nimport { isSSOPostRequest } from '../utils/refreshAccessToken/helpers';\n\nconst logger = fronteggLogger.child({ tag: 'FronteggApiMiddleware.ProxyResponseCallback' });\n/**\n * Proxy response callback fired on after each response from Frontegg services,\n * to transport frontegg modify cookies and generating encrypted JWT session cookie.\n *\n * @param {IncomingMessage} proxyRes - Proxy response from Frontegg services\n * @param {NextApiRequest} req - Next.js request sent from client-side\n * @param {NextApiResponse} res - Next.js response to send to client-side\n */\nconst ProxyResponseCallback: ProxyResCallback<IncomingMessage, NextApiResponse> = (proxyRes, req, res) => {\n let buffer = new Buffer('');\n let totalLength: number = 0;\n const isSecured = new URL(config.appUrl).protocol === 'https:';\n\n proxyRes.on('data', (chunk: Buffer) => {\n totalLength += chunk.length;\n buffer = Buffer.concat([buffer, chunk], totalLength);\n });\n proxyRes.on('end', async () => {\n try {\n const url = req.url!;\n const statusCode = proxyRes.statusCode ?? 500;\n const isSuccess = statusCode >= 200 && statusCode < 400;\n const bodyStr = buffer.toString('utf-8');\n const isLogout = isFronteggLogoutUrl(url);\n\n if (isLogout) {\n CookieManager.removeCookies({\n isSecured,\n cookieDomain: config.cookieDomain,\n res,\n req,\n });\n res.status(statusCode).end(bodyStr);\n return;\n }\n\n if (isSuccess) {\n const cookies = CookieManager.modifySetCookie(proxyRes.headers['set-cookie'], isSecured) ?? [];\n\n try {\n if (bodyStr && bodyStr.length > 0) {\n const body = JSON.parse(bodyStr);\n if (body.accessToken || body.access_token) {\n const [session, decodedJwt] = await createSessionFromAccessToken(body);\n if (session) {\n const sessionCookie = CookieManager.create({\n value: session,\n expires: new Date(decodedJwt.exp * 1000),\n secure: isSecured,\n req,\n });\n cookies.push(...sessionCookie);\n }\n }\n }\n } catch (e) {\n /** ignore api call if:\n * - Does not have accessToken / access_token\n * - Not json response\n */\n if (statusCode === 302 && isSSOPostRequest(url)) {\n /**\n * Ignore saml/oidc postLogin response with redirect\n */\n } else {\n logger.error('failed to create session', e, {\n url,\n statusCode,\n });\n }\n }\n Object.keys(proxyRes.headers)\n .filter((header) => header !== 'cookie')\n .forEach((header) => {\n res.setHeader(header, `${proxyRes.headers[header]}`);\n });\n res.setHeader('set-cookie', cookies);\n res.status(statusCode).end(bodyStr);\n } else {\n if (statusCode >= 400 && statusCode !== 404) {\n logger.error(`Middleware request failed statusCode: ${statusCode} for url: ${url}`);\n }\n Object.keys(proxyRes.headers)\n .filter((header) => header !== 'cookie')\n .forEach((header) => {\n res.setHeader(header, `${proxyRes.headers[header]}`);\n });\n res.status(statusCode).end(bodyStr);\n }\n } catch (e: any) {\n logger.error('proxy failed to send request', e);\n res.status(500).end('Internal Server Error');\n }\n });\n};\n\nexport default ProxyResponseCallback;\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAEA,MA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AAK;UACnBpD,GAAG,CAACsD,SAAS,CAACF,MAAM,EAAG,GAAEtD,QAAQ,CAAC+B,OAAO,CAACuB,MAAM,CAAE,EAAC,CAAC;QACtD,CAAC,CAAC;QACJpD,GAAG,CAACsD,SAAS,CAAC,YAAY,EAAE3B,OAAO,CAAC;QACpC3B,GAAG,CAACwB,MAAM,CAACT,UAAU,CAAC,CAACU,GAAG,CAACR,OAAO,CAAC;MACrC,CAAC,MAAM;QACL,IAAIF,UAAU,IAAI,GAAG,IAAIA,UAAU,KAAK,GAAG,EAAE;UAC3CtB,MAAM,CAACuD,KAAK,CAAE,yCAAwCjC,UAAW,aAAYD,GAAI,EAAC,CAAC;QACrF;QACAmC,MAAM,CAACC,IAAI,CAACpD,QAAQ,CAAC+B,OAAO,CAAC,CAC1BsB,MAAM,CAAEC,MAAM,IAAKA,MAAM,KAAK,QAAQ,CAAC,CACvCC,OAAO,CAAED,MAAM,IAAK;UACnBpD,GAAG,CAACsD,SAAS,CAACF,MAAM,EAAG,GAAEtD,QAAQ,CAAC+B,OAAO,CAACuB,MAAM,CAAE,EAAC,CAAC;QACtD,CAAC,CAAC;QACJpD,GAAG,CAACwB,MAAM,CAACT,UAAU,CAAC,CAACU,GAAG,CAACR,OAAO,CAAC;MACrC;IACF,CAAC,CAAC,OAAO6B,CAAM,EAAE;MACfrD,MAAM,CAACuD,KAAK,CAAC,8BAA8B,EAAEF,CAAC,CAAC;MAC/C9C,GAAG,CAACwB,MAAM,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,uBAAuB,CAAC;IAC9C;EACF,CAAC,CAAC;AACJ,CAAC;AAAC,IAAA8B,QAAA,GAEa1D,qBAAqB;AAAA2D,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frontegg/nextjs",
3
3
  "libName": "FronteggNextJs",
4
- "version": "8.0.11-alpha.7463014450",
4
+ "version": "8.0.11-alpha.7600753901",
5
5
  "author": "Frontegg LTD",
6
6
  "license": "MIT",
7
7
  "repository": {
package/sdkVersion.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _default = {
8
- version: '8.0.11-alpha.7463014450'
8
+ version: '8.0.11-alpha.7600753901'
9
9
  };
10
10
  exports.default = _default;
11
11
  //# sourceMappingURL=sdkVersion.js.map
package/sdkVersion.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sdkVersion.js","names":["version","exports","default","_default"],"sources":["../../../packages/nextjs/src/sdkVersion.ts"],"sourcesContent":["export default { version: '8.0.11-alpha.7463014450' };\n"],"mappings":";;;;;;eAAe;EAAEA,OAAO,EAAE;AAA0B,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAC,QAAA"}
1
+ {"version":3,"file":"sdkVersion.js","names":["version","exports","default","_default"],"sources":["../../../packages/nextjs/src/sdkVersion.ts"],"sourcesContent":["export default { version: '8.0.11-alpha.7600753901' };\n"],"mappings":";;;;;;eAAe;EAAEA,OAAO,EAAE;AAA0B,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAC,QAAA"}