@frontegg/nextjs 6.7.14 → 6.7.15-alpha.4076761575

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,12 @@
1
1
  # Change Log
2
2
 
3
+ ## [6.7.15](https://github.com/frontegg/frontegg-nextjs/compare/v6.7.14...v6.7.15) (2023-2-2)
4
+
5
+
6
+ ### NextJS Wrapper 6.7.15:
7
+ - FR-10557 - Add playwright tests for FornteggMiddleware
8
+ - FR-10557 - Add playwright for testing + Fix cookie parsing
9
+
3
10
  ## [6.7.14](https://github.com/frontegg/frontegg-nextjs/compare/v6.7.13...v6.7.14) (2023-2-1)
4
11
 
5
12
 
@@ -100,7 +100,7 @@ var FronteggConfig = /** @class */ (function () {
100
100
  data = _b.sent();
101
101
  publicKey = data.keys.find(function (key) { return key.kty === 'RSA'; });
102
102
  _a = this;
103
- return [4 /*yield*/, importJWK(publicKey)];
103
+ return [4 /*yield*/, importJWK(publicKey, 'PS256')];
104
104
  case 3:
105
105
  _a._jwtPublicKey = _b.sent();
106
106
  _b.label = 4;
@@ -147,7 +147,7 @@ var CookieManager = /** @class */ (function () {
147
147
  return cookieNumber ? "".concat(cookieName, "-").concat(cookieNumber) : cookieName;
148
148
  };
149
149
  this.mapValueChunksToCookies = function (cookieName, valueChunks, options) {
150
- return valueChunks.map(function (chunk, index) { return cookie.serialize(_this.getCookieName(index + 1, cookieName), chunk, options); });
150
+ return valueChunks.map(function (chunk, index) { return cookie.serialize(_this.getCookieName(index + 1, cookieName), chunk, options) + ';'; });
151
151
  };
152
152
  this.getCookieStringFromRequest = function (req) {
153
153
  return 'credentials' in req ? req.headers.get('cookie') || '' : req.headers.cookie || '';
@@ -262,8 +262,8 @@ var CookieManager = /** @class */ (function () {
262
262
  };
263
263
  CookieManager.prototype.splitValueToChunks = function (cookieName, value, options) {
264
264
  var cookieOptionLength = cookie.serialize(this.getCookieName(1, cookieName), '', options).length;
265
- var maxValueLength = COOKIE_MAX_LENGTH - cookieOptionLength;
266
- return chunkString(value, maxValueLength);
265
+ var chunkSize = COOKIE_MAX_LENGTH - cookieOptionLength - 1;
266
+ return chunkString(value, chunkSize);
267
267
  };
268
268
  CookieManager.prototype.getParsedCookieFromRequest = function (req) {
269
269
  if (!req) {
@@ -319,4 +319,4 @@ var CookieManager = /** @class */ (function () {
319
319
  var CookieManager$1 = new CookieManager();
320
320
 
321
321
  export { CookieManager$1 as C, FronteggConfig$1 as F, COOKIE_MAX_LENGTH as a, fronteggErrors as f };
322
- //# sourceMappingURL=CookieManager-09a8df0d.js.map
322
+ //# sourceMappingURL=CookieManager-b6f805c7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CookieManager-b6f805c7.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/client/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { __assign, __spreadArray } from 'tslib';
3
- import { F as FronteggConfig } from '../CookieManager-09a8df0d.js';
3
+ import { F as FronteggConfig } from '../CookieManager-b6f805c7.js';
4
4
  import 'iron-session';
5
5
  import 'jose';
6
6
  import '../api-25516652.js';
package/common/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export { a as COOKIE_MAX_LENGTH, C as CookieManager, F as FronteggConfig, f as fronteggErrors } from '../CookieManager-09a8df0d.js';
2
- export { c as createSessionFromAccessToken, a as getAllUserData, g as getTokensFromCookie } from '../helpers-d1972132.js';
3
- export { c as createGetSession } from '../createGetSession-59d7e8fc.js';
1
+ export { a as COOKIE_MAX_LENGTH, C as CookieManager, F as FronteggConfig, f as fronteggErrors } from '../CookieManager-b6f805c7.js';
2
+ export { c as createSessionFromAccessToken, a as getAllUserData, g as getTokensFromCookie } from '../helpers-b3f731cb.js';
3
+ export { c as createGetSession } from '../createGetSession-ec910389.js';
4
4
  import 'tslib';
5
5
  import 'cookie';
6
6
  import 'jose';
@@ -1,6 +1,6 @@
1
1
  import { __awaiter, __generator } from 'tslib';
2
2
  import { jwtVerify } from 'jose';
3
- import { F as FronteggConfig } from './CookieManager-09a8df0d.js';
3
+ import { F as FronteggConfig } from './CookieManager-b6f805c7.js';
4
4
 
5
5
  var createGetSession = function (_a) {
6
6
  var getCookie = _a.getCookie, cookieResolver = _a.cookieResolver;
@@ -47,4 +47,4 @@ var createGetSession = function (_a) {
47
47
  };
48
48
 
49
49
  export { createGetSession as c };
50
- //# sourceMappingURL=createGetSession-59d7e8fc.js.map
50
+ //# sourceMappingURL=createGetSession-ec910389.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createGetSession-ec910389.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/edge/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { __awaiter, __generator } from 'tslib';
2
2
  import { unsealData } from 'iron-session/edge';
3
- import { C as CookieManager, F as FronteggConfig } from '../CookieManager-09a8df0d.js';
4
- import { c as createGetSession } from '../createGetSession-59d7e8fc.js';
3
+ import { C as CookieManager, F as FronteggConfig } from '../CookieManager-b6f805c7.js';
4
+ import { c as createGetSession } from '../createGetSession-ec910389.js';
5
5
  import 'cookie';
6
6
  import 'jose';
7
7
 
@@ -4,7 +4,7 @@ import { jwtVerify } from 'jose';
4
4
  import { g as getUsers, a as getTenants } from './api-25516652.js';
5
5
  import 'react';
6
6
  import '@frontegg/react-hooks';
7
- import { F as FronteggConfig } from './CookieManager-09a8df0d.js';
7
+ import { F as FronteggConfig } from './CookieManager-b6f805c7.js';
8
8
 
9
9
  var calculateExpiresInFromExp = function (exp) { return Math.floor((exp * 1000 - Date.now()) / 1000); };
10
10
 
@@ -58,27 +58,28 @@ function getTokensFromCookie(cookie) {
58
58
  var getAllUserData = function (_a) {
59
59
  var getSession = _a.getSession, reqHeaders = _a.reqHeaders;
60
60
  return __awaiter(void 0, void 0, void 0, function () {
61
- var session, headers, _b, baseUser, tenants, user;
62
- return __generator(this, function (_d) {
63
- switch (_d.label) {
61
+ var session, headers, _b, baseUser, tenants, user, e_1;
62
+ return __generator(this, function (_c) {
63
+ switch (_c.label) {
64
64
  case 0:
65
- _d.trys.push([0, 3, , 4]);
65
+ _c.trys.push([0, 3, , 4]);
66
66
  return [4 /*yield*/, getSession()];
67
67
  case 1:
68
- session = _d.sent();
68
+ session = _c.sent();
69
69
  if (!session)
70
70
  return [2 /*return*/, {}];
71
71
  headers = __assign(__assign({}, reqHeaders), { Authorization: "Bearer ".concat(session.accessToken) });
72
72
  return [4 /*yield*/, Promise.all([getUsers(headers), getTenants(headers)])];
73
73
  case 2:
74
- _b = _d.sent(), baseUser = _b[0], tenants = _b[1];
74
+ _b = _c.sent(), baseUser = _b[0], tenants = _b[1];
75
75
  if (!baseUser || !tenants)
76
76
  return [2 /*return*/, {}];
77
77
  user = baseUser && session
78
78
  ? __assign(__assign(__assign({}, session.user), baseUser), { expiresIn: calculateExpiresInFromExp(session.user.exp) }) : undefined;
79
79
  return [2 /*return*/, { user: user, session: session, tenants: tenants }];
80
80
  case 3:
81
- _d.sent();
81
+ e_1 = _c.sent();
82
+ console.error(e_1);
82
83
  return [2 /*return*/, {}];
83
84
  case 4: return [2 /*return*/];
84
85
  }
@@ -87,4 +88,4 @@ var getAllUserData = function (_a) {
87
88
  };
88
89
 
89
90
  export { getAllUserData as a, createSessionFromAccessToken as c, getTokensFromCookie as g };
90
- //# sourceMappingURL=helpers-d1972132.js.map
91
+ //# sourceMappingURL=helpers-b3f731cb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers-b3f731cb.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/index.js CHANGED
@@ -323,7 +323,7 @@ var FronteggConfig = /** @class */ (function () {
323
323
  data = _b.sent();
324
324
  publicKey = data.keys.find(function (key) { return key.kty === 'RSA'; });
325
325
  _a = this;
326
- return [4 /*yield*/, jose.importJWK(publicKey)];
326
+ return [4 /*yield*/, jose.importJWK(publicKey, 'PS256')];
327
327
  case 3:
328
328
  _a._jwtPublicKey = _b.sent();
329
329
  _b.label = 4;
@@ -446,27 +446,28 @@ function getTokensFromCookie(cookie) {
446
446
  var getAllUserData = function (_a) {
447
447
  var getSession = _a.getSession, reqHeaders = _a.reqHeaders;
448
448
  return tslib.__awaiter(void 0, void 0, void 0, function () {
449
- var session, headers, _b, baseUser, tenants, user;
450
- return tslib.__generator(this, function (_d) {
451
- switch (_d.label) {
449
+ var session, headers, _b, baseUser, tenants, user, e_1;
450
+ return tslib.__generator(this, function (_c) {
451
+ switch (_c.label) {
452
452
  case 0:
453
- _d.trys.push([0, 3, , 4]);
453
+ _c.trys.push([0, 3, , 4]);
454
454
  return [4 /*yield*/, getSession()];
455
455
  case 1:
456
- session = _d.sent();
456
+ session = _c.sent();
457
457
  if (!session)
458
458
  return [2 /*return*/, {}];
459
459
  headers = tslib.__assign(tslib.__assign({}, reqHeaders), { Authorization: "Bearer ".concat(session.accessToken) });
460
460
  return [4 /*yield*/, Promise.all([getUsers(headers), getTenants(headers)])];
461
461
  case 2:
462
- _b = _d.sent(), baseUser = _b[0], tenants = _b[1];
462
+ _b = _c.sent(), baseUser = _b[0], tenants = _b[1];
463
463
  if (!baseUser || !tenants)
464
464
  return [2 /*return*/, {}];
465
465
  user = baseUser && session
466
466
  ? tslib.__assign(tslib.__assign(tslib.__assign({}, session.user), baseUser), { expiresIn: calculateExpiresInFromExp(session.user.exp) }) : undefined;
467
467
  return [2 /*return*/, { user: user, session: session, tenants: tenants }];
468
468
  case 3:
469
- _d.sent();
469
+ e_1 = _c.sent();
470
+ console.error(e_1);
470
471
  return [2 /*return*/, {}];
471
472
  case 4: return [2 /*return*/];
472
473
  }
@@ -545,7 +546,7 @@ var CookieManager = /** @class */ (function () {
545
546
  return cookieNumber ? "".concat(cookieName, "-").concat(cookieNumber) : cookieName;
546
547
  };
547
548
  this.mapValueChunksToCookies = function (cookieName, valueChunks, options) {
548
- return valueChunks.map(function (chunk, index) { return cookie__default["default"].serialize(_this.getCookieName(index + 1, cookieName), chunk, options); });
549
+ return valueChunks.map(function (chunk, index) { return cookie__default["default"].serialize(_this.getCookieName(index + 1, cookieName), chunk, options) + ';'; });
549
550
  };
550
551
  this.getCookieStringFromRequest = function (req) {
551
552
  return 'credentials' in req ? req.headers.get('cookie') || '' : req.headers.cookie || '';
@@ -660,8 +661,8 @@ var CookieManager = /** @class */ (function () {
660
661
  };
661
662
  CookieManager.prototype.splitValueToChunks = function (cookieName, value, options) {
662
663
  var cookieOptionLength = cookie__default["default"].serialize(this.getCookieName(1, cookieName), '', options).length;
663
- var maxValueLength = COOKIE_MAX_LENGTH - cookieOptionLength;
664
- return chunkString(value, maxValueLength);
664
+ var chunkSize = COOKIE_MAX_LENGTH - cookieOptionLength - 1;
665
+ return chunkString(value, chunkSize);
665
666
  };
666
667
  CookieManager.prototype.getParsedCookieFromRequest = function (req) {
667
668
  if (!req) {
@@ -768,43 +769,6 @@ function FronteggRouterProps(context) {
768
769
  };
769
770
  }
770
771
 
771
- var getSession = function (req) {
772
- return createGetSession({
773
- getCookie: function () { return CookieManager$1.getParsedCookieFromRequest(req); },
774
- cookieResolver: getTokensFromCookie,
775
- });
776
- };
777
- function withSSRSession(handler) {
778
- var _this = this;
779
- return function (context) { return tslib.__awaiter(_this, void 0, void 0, function () {
780
- var session, loginUrl;
781
- var _a, _b;
782
- return tslib.__generator(this, function (_c) {
783
- switch (_c.label) {
784
- case 0: return [4 /*yield*/, getSession(context.req)];
785
- case 1:
786
- session = _c.sent();
787
- if (session) {
788
- return [2 /*return*/, handler(context, session)];
789
- }
790
- else {
791
- loginUrl = (_a = fronteggConfig.authRoutes.loginUrl) !== null && _a !== void 0 ? _a : reduxStore.authInitialState.routes.loginUrl;
792
- if (!loginUrl.startsWith('/')) {
793
- loginUrl = "/".concat(loginUrl);
794
- }
795
- return [2 /*return*/, {
796
- redirect: {
797
- permanent: false,
798
- destination: "".concat(loginUrl, "?redirectUrl=").concat(encodeURIComponent((_b = context.resolvedUrl) !== null && _b !== void 0 ? _b : context.req.url)),
799
- },
800
- props: {},
801
- }];
802
- }
803
- }
804
- });
805
- }); };
806
- }
807
-
808
772
  function refreshTokenHostedLogin(ctx, headers) {
809
773
  return tslib.__awaiter(this, void 0, void 0, function () {
810
774
  var sealFromCookies, tokens;
@@ -856,8 +820,6 @@ function refreshTokenEmbedded(ctx, headers, cookies) {
856
820
  return cookie.replace(/-/g, '') === refreshTokenKey;
857
821
  });
858
822
  if (!cookieKey) {
859
- // ctx.res?.setHeader('set-cookie', removedCookies);
860
- // remove all fe_nextjs-session cookies
861
823
  return [2 /*return*/, null];
862
824
  }
863
825
  return [4 /*yield*/, fetch("".concat(process.env['FRONTEGG_BASE_URL'], "/frontegg").concat(restApi.fronteggRefreshTokenUrl), {
@@ -880,32 +842,18 @@ function refreshTokenEmbedded(ctx, headers, cookies) {
880
842
  });
881
843
  }
882
844
  function refreshToken(ctx) {
883
- var _a;
845
+ var _a, _b;
884
846
  return tslib.__awaiter(this, void 0, void 0, function () {
885
- var request, session, isSecured, headers, cookies, response, data, rewriteCookieDomainConfig, cookieHeader, newSetCookie, _b, session, decodedJwt, refreshToken_1, cookieValue;
886
- var _c;
887
- return tslib.__generator(this, function (_d) {
888
- switch (_d.label) {
847
+ var request, isSecured, headers, cookies, response, data, cookieHeader, newSetCookie, _c, session, decodedJwt, refreshToken_1, cookieValue, e_2;
848
+ var _d;
849
+ return tslib.__generator(this, function (_e) {
850
+ switch (_e.label) {
889
851
  case 0:
890
- _d.trys.push([0, 13, , 14]);
852
+ _e.trys.push([0, 7, , 8]);
891
853
  request = ctx.req;
892
854
  if (!request) {
893
855
  return [2 /*return*/, null];
894
856
  }
895
- _d.label = 1;
896
- case 1:
897
- _d.trys.push([1, 3, , 4]);
898
- return [4 /*yield*/, getSession(ctx.req)];
899
- case 2:
900
- session = _d.sent();
901
- if (session) {
902
- return [2 /*return*/, session];
903
- }
904
- return [3 /*break*/, 4];
905
- case 3:
906
- _d.sent();
907
- return [3 /*break*/, 4];
908
- case 4:
909
857
  isSecured = new URL(fronteggConfig.appUrl).protocol === 'https:';
910
858
  headers = request.headers;
911
859
  cookies = request.cookies;
@@ -913,17 +861,17 @@ function refreshToken(ctx) {
913
861
  return [2 /*return*/, null];
914
862
  }
915
863
  response = void 0;
916
- if (!fronteggConfig.fronteggAppOptions.hostedLoginBox) return [3 /*break*/, 6];
864
+ if (!fronteggConfig.fronteggAppOptions.hostedLoginBox) return [3 /*break*/, 2];
917
865
  return [4 /*yield*/, refreshTokenHostedLogin(ctx, headers)];
918
- case 5:
919
- response = _d.sent();
920
- return [3 /*break*/, 8];
921
- case 6: return [4 /*yield*/, refreshTokenEmbedded(ctx, headers, cookies)];
922
- case 7:
923
- response = _d.sent();
924
- _d.label = 8;
925
- case 8:
926
- if (!response) {
866
+ case 1:
867
+ response = _e.sent();
868
+ return [3 /*break*/, 4];
869
+ case 2: return [4 /*yield*/, refreshTokenEmbedded(ctx, headers, cookies)];
870
+ case 3:
871
+ response = _e.sent();
872
+ _e.label = 4;
873
+ case 4:
874
+ if (response === null || !response.ok) {
927
875
  CookieManager$1.removeCookies({
928
876
  isSecured: isSecured,
929
877
  cookieDomain: fronteggConfig.cookieDomain,
@@ -932,18 +880,17 @@ function refreshToken(ctx) {
932
880
  });
933
881
  return [2 /*return*/, null];
934
882
  }
935
- if (!response.ok) return [3 /*break*/, 11];
936
- return [4 /*yield*/, response.text()];
937
- case 9:
938
- data = _d.sent();
939
- rewriteCookieDomainConfig = (_c = {},
940
- _c[fronteggConfig.baseUrlHost] = fronteggConfig.cookieDomain,
941
- _c);
883
+ return [4 /*yield*/, response.json()];
884
+ case 5:
885
+ data = _e.sent();
886
+ (_d = {},
887
+ _d[fronteggConfig.baseUrlHost] = fronteggConfig.cookieDomain,
888
+ _d);
942
889
  cookieHeader = response.headers.raw()['set-cookie'];
943
- newSetCookie = CookieManager$1.rewriteCookieProperty(cookieHeader, rewriteCookieDomainConfig, 'domain');
890
+ newSetCookie = (_a = CookieManager$1.modifySetCookie(cookieHeader, isSecured)) !== null && _a !== void 0 ? _a : [];
944
891
  return [4 /*yield*/, createSessionFromAccessToken(data)];
945
- case 10:
946
- _b = _d.sent(), session = _b[0], decodedJwt = _b[1], refreshToken_1 = _b[2];
892
+ case 6:
893
+ _c = _e.sent(), session = _c[0], decodedJwt = _c[1], refreshToken_1 = _c[2];
947
894
  if (!session) {
948
895
  return [2 /*return*/, null];
949
896
  }
@@ -952,25 +899,21 @@ function refreshToken(ctx) {
952
899
  expires: new Date(decodedJwt.exp * 1000),
953
900
  isSecured: isSecured,
954
901
  });
955
- if (typeof newSetCookie === 'string') {
956
- newSetCookie = [newSetCookie];
957
- }
902
+ // if (typeof newSetCookie === 'string') {
903
+ // newSetCookie = [ newSetCookie ];
904
+ // }
958
905
  newSetCookie.push.apply(newSetCookie, cookieValue);
959
- (_a = ctx.res) === null || _a === void 0 ? void 0 : _a.setHeader('set-cookie', newSetCookie);
906
+ (_b = ctx.res) === null || _b === void 0 ? void 0 : _b.setHeader('set-cookie', newSetCookie);
960
907
  return [2 /*return*/, {
961
- accessToken: JSON.parse(data).accessToken,
908
+ accessToken: data.accessToken,
962
909
  user: decodedJwt,
963
910
  refreshToken: refreshToken_1,
964
911
  }];
965
- case 11:
966
- // remove all fe_nextjs-session cookies
967
- // ctx.res?.setHeader('set-cookie', removedCookies);
968
- return [2 /*return*/, null];
969
- case 12: return [3 /*break*/, 14];
970
- case 13:
971
- _d.sent();
912
+ case 7:
913
+ e_2 = _e.sent();
914
+ console.error('Failed to create session e', e_2);
972
915
  return [2 /*return*/, null];
973
- case 14: return [2 /*return*/];
916
+ case 8: return [2 /*return*/];
974
917
  }
975
918
  });
976
919
  });
@@ -1071,16 +1014,61 @@ var withFronteggApp = function (app, options) {
1071
1014
  return CustomFronteggApp;
1072
1015
  };
1073
1016
 
1017
+ var getSession = function (req) {
1018
+ return createGetSession({
1019
+ getCookie: function () { return CookieManager$1.getParsedCookieFromRequest(req); },
1020
+ cookieResolver: getTokensFromCookie,
1021
+ });
1022
+ };
1023
+ function withSSRSession(handler) {
1024
+ var _this = this;
1025
+ return function (context) { return tslib.__awaiter(_this, void 0, void 0, function () {
1026
+ var session, loginUrl;
1027
+ var _a, _b;
1028
+ return tslib.__generator(this, function (_c) {
1029
+ switch (_c.label) {
1030
+ case 0: return [4 /*yield*/, getSession(context.req)];
1031
+ case 1:
1032
+ session = _c.sent();
1033
+ if (session) {
1034
+ return [2 /*return*/, handler(context, session)];
1035
+ }
1036
+ else {
1037
+ loginUrl = (_a = fronteggConfig.authRoutes.loginUrl) !== null && _a !== void 0 ? _a : reduxStore.authInitialState.routes.loginUrl;
1038
+ if (!loginUrl.startsWith('/')) {
1039
+ loginUrl = "/".concat(loginUrl);
1040
+ }
1041
+ return [2 /*return*/, {
1042
+ redirect: {
1043
+ permanent: false,
1044
+ destination: "".concat(loginUrl, "?redirectUrl=").concat(encodeURIComponent((_b = context.resolvedUrl) !== null && _b !== void 0 ? _b : context.req.url)),
1045
+ },
1046
+ props: {},
1047
+ }];
1048
+ }
1049
+ }
1050
+ });
1051
+ }); };
1052
+ }
1053
+
1074
1054
  /**
1075
1055
  * @see https://www.npmjs.com/package/http-proxy
1076
1056
  */
1077
1057
  var FronteggProxy = httpProxy__default["default"].createProxyServer({
1078
1058
  target: process.env['FRONTEGG_BASE_URL'],
1079
- autoRewrite: false,
1080
1059
  followRedirects: true,
1060
+ changeOrigin: true,
1061
+ selfHandleResponse: true,
1081
1062
  });
1082
1063
  var proxyReqCallback = function (proxyReq, req) {
1064
+ var _a;
1083
1065
  try {
1066
+ var cookies_1 = cookie__default["default"].parse((_a = req.headers['cookie']) !== null && _a !== void 0 ? _a : '');
1067
+ Object.keys(cookies_1)
1068
+ .filter(function (cookieName) { return cookieName.startsWith('fe_') && !cookieName.startsWith(fronteggConfig.cookieName); })
1069
+ .forEach(function (cookieName) {
1070
+ proxyReq.setHeader(cookieName, cookies_1[cookieName]);
1071
+ });
1084
1072
  if (req.body) {
1085
1073
  var bodyData = JSON.stringify(req.body);
1086
1074
  // in case if content-type is application/x-www-form-urlencoded -> we need to change to application/json
@@ -1149,11 +1137,16 @@ var proxyResCallback = function (proxyRes, req, res) {
1149
1137
  return [3 /*break*/, 4];
1150
1138
  case 3:
1151
1139
  e_1 = _d.sent();
1152
- if (bodyStr !== '') {
1140
+ if (bodyStr !== '' && !process.env['FRONTEGG_TEST_URL']) {
1153
1141
  console.error('[ERROR] FronteggMiddleware', 'proxy failed to parse response body', bodyStr, e_1);
1154
1142
  }
1155
1143
  return [3 /*break*/, 4];
1156
1144
  case 4:
1145
+ Object.keys(proxyRes.headers)
1146
+ .filter(function (header) { return header !== 'cookie'; })
1147
+ .forEach(function (header) {
1148
+ res.setHeader(header, "".concat(proxyRes.headers[header]));
1149
+ });
1157
1150
  res.setHeader('set-cookie', cookies);
1158
1151
  res.status(statusCode).end(bodyStr);
1159
1152
  return [3 /*break*/, 6];
@@ -1228,10 +1221,13 @@ var middlewarePromise = function (req, res) {
1228
1221
  var _a;
1229
1222
  req.url = rewritePath((_a = req.url) !== null && _a !== void 0 ? _a : '/', fronteggPathRewrite);
1230
1223
  res.on('close', function () { return resolve(); });
1231
- FronteggProxy.web(req, res, {
1232
- changeOrigin: true,
1233
- selfHandleResponse: true,
1234
- });
1224
+ var options = {
1225
+ target: process.env['FRONTEGG_BASE_URL'],
1226
+ };
1227
+ if (process.env['FRONTEGG_TEST_URL'] && req.url == '/frontegg/middleware-test') {
1228
+ options.target = process.env['FRONTEGG_TEST_URL'];
1229
+ }
1230
+ FronteggProxy.web(req, res, options);
1235
1231
  });
1236
1232
  };
1237
1233
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frontegg/nextjs",
3
3
  "libName": "FronteggNextJs",
4
- "version": "6.7.14",
4
+ "version": "6.7.15-alpha.4076761575",
5
5
  "author": "Frontegg LTD",
6
6
  "license": "MIT",
7
7
  "types": "dist/index.d.ts",
package/server/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { __awaiter, __generator, __rest, __assign } from 'tslib';
2
2
  import React from 'react';
3
3
  import { cookies, headers } from 'next/headers';
4
- import { C as CookieManager } from '../CookieManager-09a8df0d.js';
5
- import { g as getTokensFromCookie, a as getAllUserData } from '../helpers-d1972132.js';
6
- import { c as createGetSession } from '../createGetSession-59d7e8fc.js';
4
+ import { C as CookieManager } from '../CookieManager-b6f805c7.js';
5
+ import { g as getTokensFromCookie, a as getAllUserData } from '../helpers-b3f731cb.js';
6
+ import { c as createGetSession } from '../createGetSession-ec910389.js';
7
7
  import 'jose';
8
8
  import '@frontegg/react-hooks';
9
9
  import '@frontegg/rest-api';
@@ -1 +0,0 @@
1
- {"version":3,"file":"CookieManager-09a8df0d.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"createGetSession-59d7e8fc.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers-d1972132.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}