@frontegg/nextjs 5.3.1-alpha.2448524672 → 5.4.0-alpha.2494449312

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.
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { FronteggApp } from '@frontegg/admin-portal/FronteggApp';
3
+ declare const AppContext: import("react").Context<FronteggApp | null>;
4
+ export default AppContext;
@@ -1,5 +1,6 @@
1
1
  import { KeyLike } from 'jose';
2
2
  import { AuthPageRoutes } from '@frontegg/redux-store';
3
+ import { FronteggAppOptions } from '@frontegg/types';
3
4
  export declare type PasswordsMap = {
4
5
  [id: string]: string;
5
6
  };
@@ -12,6 +13,7 @@ declare class FronteggConfig {
12
13
  private readonly _passwordsAsMap;
13
14
  private readonly _clientId;
14
15
  authRoutes: Partial<AuthPageRoutes>;
16
+ fronteggAppOptions: Partial<FronteggAppOptions>;
15
17
  constructor();
16
18
  get cookieName(): string;
17
19
  get password(): string;
package/index.cjs.js CHANGED
@@ -58,15 +58,19 @@ function __awaiter(thisArg, _arguments, P, generator) {
58
58
  });
59
59
  }
60
60
 
61
- var Connector = function Connector(_a) {
62
- var _b;
61
+ var AppContext = /*#__PURE__*/react.createContext(null);
63
62
 
64
- var router = _a.router,
65
- appName = _a.appName,
66
- props = __rest(_a, ["router", "appName"]);
63
+ var Connector = function Connector(_props) {
64
+ var _a;
65
+
66
+ var router = _props.router,
67
+ appName = _props.appName,
68
+ hostedLoginBox = _props.hostedLoginBox;
69
+ _props.customLoginBox;
70
+ var props = __rest(_props, ["router", "appName", "hostedLoginBox", "customLoginBox"]);
67
71
 
68
72
  var isSSR = typeof window === 'undefined';
69
- var baseName = (_b = props.basename) !== null && _b !== void 0 ? _b : router.basePath;
73
+ var baseName = (_a = props.basename) !== null && _a !== void 0 ? _a : router.basePath;
70
74
  var onRedirectTo = react.useCallback(function (_path, opts) {
71
75
  var path = _path;
72
76
 
@@ -88,7 +92,7 @@ var Connector = function Connector(_a) {
88
92
  var contextOptions = react.useMemo(function () {
89
93
  return {
90
94
  baseUrl: function baseUrl(path) {
91
- if (restApi.fronteggAuthApiRoutes.indexOf(path) !== -1 || path.endsWith('/postlogin') || path.endsWith('/prelogin')) {
95
+ if (restApi.fronteggAuthApiRoutes.indexOf(path) !== -1 || path.endsWith('/postlogin') || path.endsWith('/prelogin') || path === '/oauth/token') {
92
96
  return "".concat(props.envAppUrl, "/api");
93
97
  } else {
94
98
  return props.envBaseUrl;
@@ -96,7 +100,7 @@ var Connector = function Connector(_a) {
96
100
  },
97
101
  clientId: props.envClientId
98
102
  };
99
- }, [props.contextOptions]);
103
+ }, [props.envAppUrl, props.envBaseUrl, props.envClientId]);
100
104
  var app = react.useMemo(function () {
101
105
  var _a;
102
106
 
@@ -106,7 +110,11 @@ var Connector = function Connector(_a) {
106
110
  createdApp = adminPortal.AppHolder.getInstance(appName !== null && appName !== void 0 ? appName : 'default');
107
111
  } catch (e) {
108
112
  createdApp = adminPortal.initialize(Object.assign(Object.assign({}, props), {
113
+ hostedLoginBox: hostedLoginBox !== null && hostedLoginBox !== void 0 ? hostedLoginBox : false,
109
114
  basename: (_a = props.basename) !== null && _a !== void 0 ? _a : baseName,
115
+ authOptions: Object.assign(Object.assign({}, props.authOptions), {
116
+ onRedirectTo: onRedirectTo
117
+ }),
110
118
  contextOptions: Object.assign(Object.assign({
111
119
  requestCredentials: 'include'
112
120
  }, props.contextOptions), contextOptions),
@@ -115,7 +123,7 @@ var Connector = function Connector(_a) {
115
123
  }
116
124
 
117
125
  return createdApp;
118
- }, [onRedirectTo]);
126
+ }, [appName, props, hostedLoginBox, baseName, onRedirectTo, contextOptions]);
119
127
  restApi.ContextHolder.setOnRedirectTo(onRedirectTo);
120
128
  react.useEffect(function () {
121
129
  var _a; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -127,10 +135,14 @@ var Connector = function Connector(_a) {
127
135
  payload: (_a = props.session) === null || _a === void 0 ? void 0 : _a.accessToken
128
136
  });
129
137
  }, [app]);
130
- return jsxRuntime.jsx(reactHooks.FronteggStoreProvider, Object.assign({}, Object.assign(Object.assign({}, props), {
131
- app: app
132
- }), {
133
- children: props.children
138
+ return jsxRuntime.jsx(AppContext.Provider, Object.assign({
139
+ value: app
140
+ }, {
141
+ children: jsxRuntime.jsx(reactHooks.FronteggStoreProvider, Object.assign({}, Object.assign(Object.assign({}, props), {
142
+ app: app
143
+ }), {
144
+ children: props.children
145
+ }))
134
146
  }));
135
147
  };
136
148
 
@@ -143,7 +155,8 @@ var ExpireInListener = function ExpireInListener() {
143
155
  expiresIn: Math.floor((user['exp'] * 1000 - Date.now()) / 1000)
144
156
  }));
145
157
  }
146
- }, [actions, user]);
158
+ }, [actions, user]); // eslint-disable-next-line react/jsx-no-useless-fragment
159
+
147
160
  return jsxRuntime.jsx(jsxRuntime.Fragment, {});
148
161
  };
149
162
 
@@ -1047,6 +1060,7 @@ var FronteggConfig = /*#__PURE__*/function () {
1047
1060
  var _a, _b, _c;
1048
1061
 
1049
1062
  this.authRoutes = {};
1063
+ this.fronteggAppOptions = {};
1050
1064
  this._clientId = (_a = process.env['FRONTEGG_CLIENT_ID']) !== null && _a !== void 0 ? _a : '';
1051
1065
  this._cookieName = (_b = process.env['FRONTEGG_COOKIE_NAME']) !== null && _b !== void 0 ? _b : "fe_session";
1052
1066
  this._password = (_c = process.env['FRONTEGG_ENCRYPTION_PASSWORD']) !== null && _c !== void 0 ? _c : '';
@@ -1181,6 +1195,33 @@ function _toConsumableArray(arr) {
1181
1195
  }
1182
1196
 
1183
1197
  function FronteggRouter() {
1198
+ var app = react.useContext(AppContext);
1199
+
1200
+ var _useRouter = router.useRouter(),
1201
+ query = _useRouter.query;
1202
+
1203
+ var loginWithRedirect = reactHooks.useLoginWithRedirect();
1204
+ react.useEffect(function () {
1205
+ if (!app) {
1206
+ return;
1207
+ }
1208
+
1209
+ if (app.options.hostedLoginBox) {
1210
+ var routesObj = Object.assign(Object.assign({}, reduxStore.authInitialState.routes), fronteggConfig.authRoutes);
1211
+
1212
+ var _a = query,
1213
+ pathArr = _a['frontegg-router'],
1214
+ queryParams = __rest(_a, ['frontegg-router']);
1215
+
1216
+ var pathname = "/".concat(pathArr.join('/'));
1217
+
1218
+ if (pathname === routesObj.loginUrl) {
1219
+ loginWithRedirect();
1220
+ } else {
1221
+ console.log('NO', pathname, queryParams);
1222
+ }
1223
+ }
1224
+ }, [app, query, loginWithRedirect]);
1184
1225
  return '';
1185
1226
  }
1186
1227
  function FronteggRouterProps(context) {
@@ -1198,6 +1239,16 @@ function FronteggRouterProps(context) {
1198
1239
  }
1199
1240
 
1200
1241
  var notFound = routesArr.indexOf(pathname) === -1;
1242
+
1243
+ if (fronteggConfig.fronteggAppOptions.hostedLoginBox) {
1244
+ var _notFound = !(routesObj.loginUrl === pathname || routesObj.hostedLoginRedirectUrl === pathname);
1245
+
1246
+ return {
1247
+ notFound: _notFound,
1248
+ props: {}
1249
+ };
1250
+ }
1251
+
1201
1252
  return {
1202
1253
  notFound: notFound,
1203
1254
  props: {}
@@ -1261,6 +1312,115 @@ function _defineProperty(obj, key, value) {
1261
1312
  return obj;
1262
1313
  }
1263
1314
 
1315
+ function getSession(req) {
1316
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
1317
+ var sealFromCookies, jwt, publicKey, _yield$jwtVerify, payload, session;
1318
+
1319
+ return regenerator.wrap(function _callee$(_context) {
1320
+ while (1) {
1321
+ switch (_context.prev = _context.next) {
1322
+ case 0:
1323
+ _context.prev = 0;
1324
+ sealFromCookies = cookie__default["default"].parse(req.headers.cookie || '')[fronteggConfig.cookieName];
1325
+
1326
+ if (sealFromCookies) {
1327
+ _context.next = 4;
1328
+ break;
1329
+ }
1330
+
1331
+ return _context.abrupt("return", undefined);
1332
+
1333
+ case 4:
1334
+ _context.next = 6;
1335
+ return ironSession.unsealData(sealFromCookies, {
1336
+ password: fronteggConfig.passwordsAsMap
1337
+ });
1338
+
1339
+ case 6:
1340
+ jwt = _context.sent;
1341
+ _context.next = 9;
1342
+ return fronteggConfig.getJwtPublicKey();
1343
+
1344
+ case 9:
1345
+ publicKey = _context.sent;
1346
+ _context.next = 12;
1347
+ return jose.jwtVerify(jwt, publicKey);
1348
+
1349
+ case 12:
1350
+ _yield$jwtVerify = _context.sent;
1351
+ payload = _yield$jwtVerify.payload;
1352
+ session = {
1353
+ accessToken: jwt,
1354
+ user: payload
1355
+ };
1356
+
1357
+ if (!(session.user.exp * 1000 < Date.now())) {
1358
+ _context.next = 17;
1359
+ break;
1360
+ }
1361
+
1362
+ return _context.abrupt("return", undefined);
1363
+
1364
+ case 17:
1365
+ return _context.abrupt("return", session);
1366
+
1367
+ case 20:
1368
+ _context.prev = 20;
1369
+ _context.t0 = _context["catch"](0);
1370
+ console.error(_context.t0);
1371
+ return _context.abrupt("return", undefined);
1372
+
1373
+ case 24:
1374
+ case "end":
1375
+ return _context.stop();
1376
+ }
1377
+ }
1378
+ }, _callee, null, [[0, 20]]);
1379
+ }));
1380
+ }
1381
+ function withSSRSession(handler) {
1382
+ var _this = this;
1383
+
1384
+ return function (context) {
1385
+ return __awaiter(_this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
1386
+ var _a, session;
1387
+
1388
+ return regenerator.wrap(function _callee2$(_context2) {
1389
+ while (1) {
1390
+ switch (_context2.prev = _context2.next) {
1391
+ case 0:
1392
+ _context2.next = 2;
1393
+ return getSession(context.req);
1394
+
1395
+ case 2:
1396
+ session = _context2.sent;
1397
+
1398
+ if (!session) {
1399
+ _context2.next = 7;
1400
+ break;
1401
+ }
1402
+
1403
+ return _context2.abrupt("return", handler(context, session));
1404
+
1405
+ case 7:
1406
+ return _context2.abrupt("return", {
1407
+ redirect: {
1408
+ permanent: false,
1409
+ destination: "/".concat((_a = fronteggConfig.authRoutes.loginUrl) !== null && _a !== void 0 ? _a : reduxStore.authInitialState.routes.loginUrl, "?redirectUrl=").concat(encodeURIComponent(context.req.url))
1410
+ },
1411
+ props: {}
1412
+ });
1413
+
1414
+ case 8:
1415
+ case "end":
1416
+ return _context2.stop();
1417
+ }
1418
+ }
1419
+ }, _callee2);
1420
+ }));
1421
+ };
1422
+ }
1423
+
1264
1424
  function rewriteCookieProperty(header, config, property) {
1265
1425
  if (Array.isArray(header)) {
1266
1426
  return header.map(function (headerElement) {
@@ -1294,7 +1454,7 @@ function refreshToken(ctx) {
1294
1454
  var _a;
1295
1455
 
1296
1456
  return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
1297
- var request, headers, cookies, refreshTokenKey, cookieKey, response, data, rewriteCookieDomainConfig, cookieHeader, newSetCookie, _yield$createSessionF, _yield$createSessionF2, session, decodedJwt, isSecured, cookieValue;
1457
+ var request, session, headers, cookies, refreshTokenKey, cookieKey, response, data, rewriteCookieDomainConfig, cookieHeader, newSetCookie, _yield$createSessionF, _yield$createSessionF2, _session, decodedJwt, isSecured, cookieValue;
1298
1458
 
1299
1459
  return regenerator.wrap(function _callee$(_context) {
1300
1460
  while (1) {
@@ -1311,6 +1471,29 @@ function refreshToken(ctx) {
1311
1471
  return _context.abrupt("return", null);
1312
1472
 
1313
1473
  case 4:
1474
+ _context.prev = 4;
1475
+ _context.next = 7;
1476
+ return getSession(ctx.req);
1477
+
1478
+ case 7:
1479
+ session = _context.sent;
1480
+
1481
+ if (!session) {
1482
+ _context.next = 10;
1483
+ break;
1484
+ }
1485
+
1486
+ return _context.abrupt("return", session);
1487
+
1488
+ case 10:
1489
+ _context.next = 14;
1490
+ break;
1491
+
1492
+ case 12:
1493
+ _context.prev = 12;
1494
+ _context.t0 = _context["catch"](4);
1495
+
1496
+ case 14:
1314
1497
  headers = request.headers;
1315
1498
  cookies = request.cookies;
1316
1499
  refreshTokenKey = "fe_refresh_".concat(fronteggConfig.clientId).replace(/-/g, '');
@@ -1319,11 +1502,11 @@ function refreshToken(ctx) {
1319
1502
  });
1320
1503
 
1321
1504
  if (!cookieKey) {
1322
- _context.next = 36;
1505
+ _context.next = 46;
1323
1506
  break;
1324
1507
  }
1325
1508
 
1326
- _context.next = 11;
1509
+ _context.next = 21;
1327
1510
  return fetch("".concat(process.env['FRONTEGG_BASE_URL'], "/frontegg").concat(restApi.fronteggRefreshTokenUrl), {
1328
1511
  method: 'POST',
1329
1512
  credentials: 'include',
@@ -1339,42 +1522,42 @@ function refreshToken(ctx) {
1339
1522
  }
1340
1523
  });
1341
1524
 
1342
- case 11:
1525
+ case 21:
1343
1526
  response = _context.sent;
1344
1527
 
1345
1528
  if (!response.ok) {
1346
- _context.next = 36;
1529
+ _context.next = 46;
1347
1530
  break;
1348
1531
  }
1349
1532
 
1350
- _context.next = 15;
1533
+ _context.next = 25;
1351
1534
  return response.text();
1352
1535
 
1353
- case 15:
1536
+ case 25:
1354
1537
  data = _context.sent;
1355
1538
  rewriteCookieDomainConfig = _defineProperty({}, fronteggConfig.baseUrlHost, fronteggConfig.cookieDomain); // @ts-ignore
1356
1539
 
1357
1540
  cookieHeader = response.headers.raw()['set-cookie'];
1358
1541
  newSetCookie = rewriteCookieProperty(cookieHeader, rewriteCookieDomainConfig, 'domain');
1359
- _context.next = 21;
1542
+ _context.next = 31;
1360
1543
  return createSessionFromAccessToken(data);
1361
1544
 
1362
- case 21:
1545
+ case 31:
1363
1546
  _yield$createSessionF = _context.sent;
1364
1547
  _yield$createSessionF2 = _slicedToArray(_yield$createSessionF, 2);
1365
- session = _yield$createSessionF2[0];
1548
+ _session = _yield$createSessionF2[0];
1366
1549
  decodedJwt = _yield$createSessionF2[1];
1367
1550
 
1368
- if (session) {
1369
- _context.next = 27;
1551
+ if (_session) {
1552
+ _context.next = 37;
1370
1553
  break;
1371
1554
  }
1372
1555
 
1373
1556
  return _context.abrupt("return", null);
1374
1557
 
1375
- case 27:
1558
+ case 37:
1376
1559
  isSecured = new URL(fronteggConfig.appUrl).protocol === 'https:';
1377
- cookieValue = cookie__default["default"].serialize(fronteggConfig.cookieName, session, {
1560
+ cookieValue = cookie__default["default"].serialize(fronteggConfig.cookieName, _session, {
1378
1561
  expires: new Date(decodedJwt.exp * 1000),
1379
1562
  httpOnly: true,
1380
1563
  domain: fronteggConfig.cookieDomain,
@@ -1398,21 +1581,21 @@ function refreshToken(ctx) {
1398
1581
  user: decodedJwt
1399
1582
  });
1400
1583
 
1401
- case 36:
1584
+ case 46:
1402
1585
  return _context.abrupt("return", null);
1403
1586
 
1404
- case 39:
1405
- _context.prev = 39;
1406
- _context.t0 = _context["catch"](0);
1407
- console.log(_context.t0);
1587
+ case 49:
1588
+ _context.prev = 49;
1589
+ _context.t1 = _context["catch"](0);
1590
+ console.log(_context.t1);
1408
1591
  return _context.abrupt("return", null);
1409
1592
 
1410
- case 43:
1593
+ case 53:
1411
1594
  case "end":
1412
1595
  return _context.stop();
1413
1596
  }
1414
1597
  }
1415
- }, _callee, null, [[0, 39]]);
1598
+ }, _callee, null, [[0, 49], [4, 12]]);
1416
1599
  }));
1417
1600
  }
1418
1601
  function addToCookies(cookieValue, res) {
@@ -1446,38 +1629,40 @@ function removeCookies(cookieName, isSecured, cookieDomain, res) {
1446
1629
  res.setHeader('set-cookie', [].concat(_toConsumableArray(existingSetCookie), [cookieValue]));
1447
1630
  }
1448
1631
  function createSessionFromAccessToken(output) {
1449
- return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
1450
- var _JSON$parse, accessToken, decodedJwt, session;
1632
+ var _a;
1451
1633
 
1634
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
1635
+ var data, accessToken, decodedJwt, session;
1452
1636
  return regenerator.wrap(function _callee2$(_context2) {
1453
1637
  while (1) {
1454
1638
  switch (_context2.prev = _context2.next) {
1455
1639
  case 0:
1456
1640
  _context2.prev = 0;
1457
- _JSON$parse = JSON.parse(output), accessToken = _JSON$parse.accessToken;
1641
+ data = JSON.parse(output);
1642
+ accessToken = (_a = data === null || data === void 0 ? void 0 : data.accessToken) !== null && _a !== void 0 ? _a : data.access_token;
1458
1643
  decodedJwt = jose.decodeJwt(accessToken);
1459
1644
  decodedJwt.expiresIn = Math.floor((decodedJwt.exp * 1000 - Date.now()) / 1000);
1460
- _context2.next = 6;
1645
+ _context2.next = 7;
1461
1646
  return ironSession.sealData(accessToken, {
1462
1647
  password: fronteggConfig.passwordsAsMap,
1463
1648
  ttl: decodedJwt.exp
1464
1649
  });
1465
1650
 
1466
- case 6:
1651
+ case 7:
1467
1652
  session = _context2.sent;
1468
1653
  return _context2.abrupt("return", [session, decodedJwt]);
1469
1654
 
1470
- case 10:
1471
- _context2.prev = 10;
1655
+ case 11:
1656
+ _context2.prev = 11;
1472
1657
  _context2.t0 = _context2["catch"](0);
1473
1658
  return _context2.abrupt("return", []);
1474
1659
 
1475
- case 13:
1660
+ case 14:
1476
1661
  case "end":
1477
1662
  return _context2.stop();
1478
1663
  }
1479
1664
  }
1480
- }, _callee2, null, [[0, 10]]);
1665
+ }, _callee2, null, [[0, 11]]);
1481
1666
  }));
1482
1667
  }
1483
1668
  var modifySetCookieIfUnsecure = function modifySetCookieIfUnsecure(setCookieValue, isSecured) {
@@ -1667,6 +1852,7 @@ var withFronteggApp = function withFronteggApp(app, options) {
1667
1852
  };
1668
1853
 
1669
1854
  fronteggConfig.authRoutes = (_b = (_a = options === null || options === void 0 ? void 0 : options.authOptions) === null || _a === void 0 ? void 0 : _a.routes) !== null && _b !== void 0 ? _b : {};
1855
+ fronteggConfig.fronteggAppOptions = options !== null && options !== void 0 ? options : {};
1670
1856
 
1671
1857
  function CustomFronteggApp(appProps) {
1672
1858
  return jsxRuntime.jsx(FronteggProvider, Object.assign({}, options, {
@@ -1683,114 +1869,6 @@ var withFronteggApp = function withFronteggApp(app, options) {
1683
1869
  return CustomFronteggApp;
1684
1870
  };
1685
1871
 
1686
- function getSession(req) {
1687
- return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
1688
- var sealFromCookies, jwt, publicKey, _yield$jwtVerify, payload, session;
1689
-
1690
- return regenerator.wrap(function _callee$(_context) {
1691
- while (1) {
1692
- switch (_context.prev = _context.next) {
1693
- case 0:
1694
- _context.prev = 0;
1695
- sealFromCookies = cookie__default["default"].parse(req.headers.cookie || '')[fronteggConfig.cookieName];
1696
-
1697
- if (sealFromCookies) {
1698
- _context.next = 4;
1699
- break;
1700
- }
1701
-
1702
- return _context.abrupt("return", undefined);
1703
-
1704
- case 4:
1705
- _context.next = 6;
1706
- return ironSession.unsealData(sealFromCookies, {
1707
- password: fronteggConfig.passwordsAsMap
1708
- });
1709
-
1710
- case 6:
1711
- jwt = _context.sent;
1712
- _context.next = 9;
1713
- return fronteggConfig.getJwtPublicKey();
1714
-
1715
- case 9:
1716
- publicKey = _context.sent;
1717
- _context.next = 12;
1718
- return jose.jwtVerify(jwt, publicKey);
1719
-
1720
- case 12:
1721
- _yield$jwtVerify = _context.sent;
1722
- payload = _yield$jwtVerify.payload;
1723
- session = {
1724
- accessToken: jwt,
1725
- user: payload
1726
- };
1727
-
1728
- if (!(session.user.exp * 1000 < Date.now())) {
1729
- _context.next = 17;
1730
- break;
1731
- }
1732
-
1733
- return _context.abrupt("return", undefined);
1734
-
1735
- case 17:
1736
- return _context.abrupt("return", session);
1737
-
1738
- case 20:
1739
- _context.prev = 20;
1740
- _context.t0 = _context["catch"](0);
1741
- console.error(_context.t0);
1742
- return _context.abrupt("return", undefined);
1743
-
1744
- case 24:
1745
- case "end":
1746
- return _context.stop();
1747
- }
1748
- }
1749
- }, _callee, null, [[0, 20]]);
1750
- }));
1751
- }
1752
- function withSSRSession(handler) {
1753
- var _this = this;
1754
-
1755
- return function (context) {
1756
- return __awaiter(_this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
1757
- var session;
1758
- return regenerator.wrap(function _callee2$(_context2) {
1759
- while (1) {
1760
- switch (_context2.prev = _context2.next) {
1761
- case 0:
1762
- _context2.next = 2;
1763
- return getSession(context.req);
1764
-
1765
- case 2:
1766
- session = _context2.sent;
1767
-
1768
- if (!session) {
1769
- _context2.next = 7;
1770
- break;
1771
- }
1772
-
1773
- return _context2.abrupt("return", handler(context, session));
1774
-
1775
- case 7:
1776
- return _context2.abrupt("return", {
1777
- redirect: {
1778
- permanent: false,
1779
- destination: "/account/login?redirectUrl=".concat(encodeURIComponent(context.req.url))
1780
- },
1781
- props: {}
1782
- });
1783
-
1784
- case 8:
1785
- case "end":
1786
- return _context2.stop();
1787
- }
1788
- }
1789
- }, _callee2);
1790
- }));
1791
- };
1792
- }
1793
-
1794
1872
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
1795
1873
 
1796
1874
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
package/index.esm.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { useCallback, useMemo, useEffect } from 'react';
2
+ import { createContext, useCallback, useMemo, useEffect, useContext } from 'react';
3
3
  import { AppHolder, initialize } from '@frontegg/admin-portal';
4
4
  export { AdminPortal } from '@frontegg/admin-portal';
5
- import { FronteggStoreProvider, useAuthUserOrNull, useAuthActions } from '@frontegg/react-hooks';
5
+ import { FronteggStoreProvider, useAuthUserOrNull, useAuthActions, useLoginWithRedirect } from '@frontegg/react-hooks';
6
6
  export * from '@frontegg/react-hooks';
7
7
  import { fronteggAuthApiRoutes, ContextHolder, fronteggRefreshTokenUrl } from '@frontegg/rest-api';
8
8
  import { useRouter } from 'next/router';
9
- import { importJWK, decodeJwt, jwtVerify } from 'jose';
9
+ import { importJWK, jwtVerify, decodeJwt } from 'jose';
10
10
  import { authInitialState } from '@frontegg/redux-store';
11
11
  import { parse } from 'url';
12
12
  import cookie from 'cookie';
13
- import { sealData, unsealData } from 'iron-session';
13
+ import { unsealData, sealData } from 'iron-session';
14
14
  import httpProxy from 'http-proxy';
15
15
  export * from '@frontegg/types';
16
16
 
@@ -51,15 +51,19 @@ function __awaiter(thisArg, _arguments, P, generator) {
51
51
  });
52
52
  }
53
53
 
54
- var Connector = function Connector(_a) {
55
- var _b;
54
+ var AppContext = /*#__PURE__*/createContext(null);
56
55
 
57
- var router = _a.router,
58
- appName = _a.appName,
59
- props = __rest(_a, ["router", "appName"]);
56
+ var Connector = function Connector(_props) {
57
+ var _a;
58
+
59
+ var router = _props.router,
60
+ appName = _props.appName,
61
+ hostedLoginBox = _props.hostedLoginBox;
62
+ _props.customLoginBox;
63
+ var props = __rest(_props, ["router", "appName", "hostedLoginBox", "customLoginBox"]);
60
64
 
61
65
  var isSSR = typeof window === 'undefined';
62
- var baseName = (_b = props.basename) !== null && _b !== void 0 ? _b : router.basePath;
66
+ var baseName = (_a = props.basename) !== null && _a !== void 0 ? _a : router.basePath;
63
67
  var onRedirectTo = useCallback(function (_path, opts) {
64
68
  var path = _path;
65
69
 
@@ -81,7 +85,7 @@ var Connector = function Connector(_a) {
81
85
  var contextOptions = useMemo(function () {
82
86
  return {
83
87
  baseUrl: function baseUrl(path) {
84
- if (fronteggAuthApiRoutes.indexOf(path) !== -1 || path.endsWith('/postlogin') || path.endsWith('/prelogin')) {
88
+ if (fronteggAuthApiRoutes.indexOf(path) !== -1 || path.endsWith('/postlogin') || path.endsWith('/prelogin') || path === '/oauth/token') {
85
89
  return "".concat(props.envAppUrl, "/api");
86
90
  } else {
87
91
  return props.envBaseUrl;
@@ -89,7 +93,7 @@ var Connector = function Connector(_a) {
89
93
  },
90
94
  clientId: props.envClientId
91
95
  };
92
- }, [props.contextOptions]);
96
+ }, [props.envAppUrl, props.envBaseUrl, props.envClientId]);
93
97
  var app = useMemo(function () {
94
98
  var _a;
95
99
 
@@ -99,7 +103,11 @@ var Connector = function Connector(_a) {
99
103
  createdApp = AppHolder.getInstance(appName !== null && appName !== void 0 ? appName : 'default');
100
104
  } catch (e) {
101
105
  createdApp = initialize(Object.assign(Object.assign({}, props), {
106
+ hostedLoginBox: hostedLoginBox !== null && hostedLoginBox !== void 0 ? hostedLoginBox : false,
102
107
  basename: (_a = props.basename) !== null && _a !== void 0 ? _a : baseName,
108
+ authOptions: Object.assign(Object.assign({}, props.authOptions), {
109
+ onRedirectTo: onRedirectTo
110
+ }),
103
111
  contextOptions: Object.assign(Object.assign({
104
112
  requestCredentials: 'include'
105
113
  }, props.contextOptions), contextOptions),
@@ -108,7 +116,7 @@ var Connector = function Connector(_a) {
108
116
  }
109
117
 
110
118
  return createdApp;
111
- }, [onRedirectTo]);
119
+ }, [appName, props, hostedLoginBox, baseName, onRedirectTo, contextOptions]);
112
120
  ContextHolder.setOnRedirectTo(onRedirectTo);
113
121
  useEffect(function () {
114
122
  var _a; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -120,10 +128,14 @@ var Connector = function Connector(_a) {
120
128
  payload: (_a = props.session) === null || _a === void 0 ? void 0 : _a.accessToken
121
129
  });
122
130
  }, [app]);
123
- return jsx(FronteggStoreProvider, Object.assign({}, Object.assign(Object.assign({}, props), {
124
- app: app
125
- }), {
126
- children: props.children
131
+ return jsx(AppContext.Provider, Object.assign({
132
+ value: app
133
+ }, {
134
+ children: jsx(FronteggStoreProvider, Object.assign({}, Object.assign(Object.assign({}, props), {
135
+ app: app
136
+ }), {
137
+ children: props.children
138
+ }))
127
139
  }));
128
140
  };
129
141
 
@@ -136,7 +148,8 @@ var ExpireInListener = function ExpireInListener() {
136
148
  expiresIn: Math.floor((user['exp'] * 1000 - Date.now()) / 1000)
137
149
  }));
138
150
  }
139
- }, [actions, user]);
151
+ }, [actions, user]); // eslint-disable-next-line react/jsx-no-useless-fragment
152
+
140
153
  return jsx(Fragment, {});
141
154
  };
142
155
 
@@ -1040,6 +1053,7 @@ var FronteggConfig = /*#__PURE__*/function () {
1040
1053
  var _a, _b, _c;
1041
1054
 
1042
1055
  this.authRoutes = {};
1056
+ this.fronteggAppOptions = {};
1043
1057
  this._clientId = (_a = process.env['FRONTEGG_CLIENT_ID']) !== null && _a !== void 0 ? _a : '';
1044
1058
  this._cookieName = (_b = process.env['FRONTEGG_COOKIE_NAME']) !== null && _b !== void 0 ? _b : "fe_session";
1045
1059
  this._password = (_c = process.env['FRONTEGG_ENCRYPTION_PASSWORD']) !== null && _c !== void 0 ? _c : '';
@@ -1174,6 +1188,33 @@ function _toConsumableArray(arr) {
1174
1188
  }
1175
1189
 
1176
1190
  function FronteggRouter() {
1191
+ var app = useContext(AppContext);
1192
+
1193
+ var _useRouter = useRouter(),
1194
+ query = _useRouter.query;
1195
+
1196
+ var loginWithRedirect = useLoginWithRedirect();
1197
+ useEffect(function () {
1198
+ if (!app) {
1199
+ return;
1200
+ }
1201
+
1202
+ if (app.options.hostedLoginBox) {
1203
+ var routesObj = Object.assign(Object.assign({}, authInitialState.routes), fronteggConfig.authRoutes);
1204
+
1205
+ var _a = query,
1206
+ pathArr = _a['frontegg-router'],
1207
+ queryParams = __rest(_a, ['frontegg-router']);
1208
+
1209
+ var pathname = "/".concat(pathArr.join('/'));
1210
+
1211
+ if (pathname === routesObj.loginUrl) {
1212
+ loginWithRedirect();
1213
+ } else {
1214
+ console.log('NO', pathname, queryParams);
1215
+ }
1216
+ }
1217
+ }, [app, query, loginWithRedirect]);
1177
1218
  return '';
1178
1219
  }
1179
1220
  function FronteggRouterProps(context) {
@@ -1191,6 +1232,16 @@ function FronteggRouterProps(context) {
1191
1232
  }
1192
1233
 
1193
1234
  var notFound = routesArr.indexOf(pathname) === -1;
1235
+
1236
+ if (fronteggConfig.fronteggAppOptions.hostedLoginBox) {
1237
+ var _notFound = !(routesObj.loginUrl === pathname || routesObj.hostedLoginRedirectUrl === pathname);
1238
+
1239
+ return {
1240
+ notFound: _notFound,
1241
+ props: {}
1242
+ };
1243
+ }
1244
+
1194
1245
  return {
1195
1246
  notFound: notFound,
1196
1247
  props: {}
@@ -1254,6 +1305,115 @@ function _defineProperty(obj, key, value) {
1254
1305
  return obj;
1255
1306
  }
1256
1307
 
1308
+ function getSession(req) {
1309
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
1310
+ var sealFromCookies, jwt, publicKey, _yield$jwtVerify, payload, session;
1311
+
1312
+ return regenerator.wrap(function _callee$(_context) {
1313
+ while (1) {
1314
+ switch (_context.prev = _context.next) {
1315
+ case 0:
1316
+ _context.prev = 0;
1317
+ sealFromCookies = cookie.parse(req.headers.cookie || '')[fronteggConfig.cookieName];
1318
+
1319
+ if (sealFromCookies) {
1320
+ _context.next = 4;
1321
+ break;
1322
+ }
1323
+
1324
+ return _context.abrupt("return", undefined);
1325
+
1326
+ case 4:
1327
+ _context.next = 6;
1328
+ return unsealData(sealFromCookies, {
1329
+ password: fronteggConfig.passwordsAsMap
1330
+ });
1331
+
1332
+ case 6:
1333
+ jwt = _context.sent;
1334
+ _context.next = 9;
1335
+ return fronteggConfig.getJwtPublicKey();
1336
+
1337
+ case 9:
1338
+ publicKey = _context.sent;
1339
+ _context.next = 12;
1340
+ return jwtVerify(jwt, publicKey);
1341
+
1342
+ case 12:
1343
+ _yield$jwtVerify = _context.sent;
1344
+ payload = _yield$jwtVerify.payload;
1345
+ session = {
1346
+ accessToken: jwt,
1347
+ user: payload
1348
+ };
1349
+
1350
+ if (!(session.user.exp * 1000 < Date.now())) {
1351
+ _context.next = 17;
1352
+ break;
1353
+ }
1354
+
1355
+ return _context.abrupt("return", undefined);
1356
+
1357
+ case 17:
1358
+ return _context.abrupt("return", session);
1359
+
1360
+ case 20:
1361
+ _context.prev = 20;
1362
+ _context.t0 = _context["catch"](0);
1363
+ console.error(_context.t0);
1364
+ return _context.abrupt("return", undefined);
1365
+
1366
+ case 24:
1367
+ case "end":
1368
+ return _context.stop();
1369
+ }
1370
+ }
1371
+ }, _callee, null, [[0, 20]]);
1372
+ }));
1373
+ }
1374
+ function withSSRSession(handler) {
1375
+ var _this = this;
1376
+
1377
+ return function (context) {
1378
+ return __awaiter(_this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
1379
+ var _a, session;
1380
+
1381
+ return regenerator.wrap(function _callee2$(_context2) {
1382
+ while (1) {
1383
+ switch (_context2.prev = _context2.next) {
1384
+ case 0:
1385
+ _context2.next = 2;
1386
+ return getSession(context.req);
1387
+
1388
+ case 2:
1389
+ session = _context2.sent;
1390
+
1391
+ if (!session) {
1392
+ _context2.next = 7;
1393
+ break;
1394
+ }
1395
+
1396
+ return _context2.abrupt("return", handler(context, session));
1397
+
1398
+ case 7:
1399
+ return _context2.abrupt("return", {
1400
+ redirect: {
1401
+ permanent: false,
1402
+ destination: "/".concat((_a = fronteggConfig.authRoutes.loginUrl) !== null && _a !== void 0 ? _a : authInitialState.routes.loginUrl, "?redirectUrl=").concat(encodeURIComponent(context.req.url))
1403
+ },
1404
+ props: {}
1405
+ });
1406
+
1407
+ case 8:
1408
+ case "end":
1409
+ return _context2.stop();
1410
+ }
1411
+ }
1412
+ }, _callee2);
1413
+ }));
1414
+ };
1415
+ }
1416
+
1257
1417
  function rewriteCookieProperty(header, config, property) {
1258
1418
  if (Array.isArray(header)) {
1259
1419
  return header.map(function (headerElement) {
@@ -1287,7 +1447,7 @@ function refreshToken(ctx) {
1287
1447
  var _a;
1288
1448
 
1289
1449
  return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
1290
- var request, headers, cookies, refreshTokenKey, cookieKey, response, data, rewriteCookieDomainConfig, cookieHeader, newSetCookie, _yield$createSessionF, _yield$createSessionF2, session, decodedJwt, isSecured, cookieValue;
1450
+ var request, session, headers, cookies, refreshTokenKey, cookieKey, response, data, rewriteCookieDomainConfig, cookieHeader, newSetCookie, _yield$createSessionF, _yield$createSessionF2, _session, decodedJwt, isSecured, cookieValue;
1291
1451
 
1292
1452
  return regenerator.wrap(function _callee$(_context) {
1293
1453
  while (1) {
@@ -1304,6 +1464,29 @@ function refreshToken(ctx) {
1304
1464
  return _context.abrupt("return", null);
1305
1465
 
1306
1466
  case 4:
1467
+ _context.prev = 4;
1468
+ _context.next = 7;
1469
+ return getSession(ctx.req);
1470
+
1471
+ case 7:
1472
+ session = _context.sent;
1473
+
1474
+ if (!session) {
1475
+ _context.next = 10;
1476
+ break;
1477
+ }
1478
+
1479
+ return _context.abrupt("return", session);
1480
+
1481
+ case 10:
1482
+ _context.next = 14;
1483
+ break;
1484
+
1485
+ case 12:
1486
+ _context.prev = 12;
1487
+ _context.t0 = _context["catch"](4);
1488
+
1489
+ case 14:
1307
1490
  headers = request.headers;
1308
1491
  cookies = request.cookies;
1309
1492
  refreshTokenKey = "fe_refresh_".concat(fronteggConfig.clientId).replace(/-/g, '');
@@ -1312,11 +1495,11 @@ function refreshToken(ctx) {
1312
1495
  });
1313
1496
 
1314
1497
  if (!cookieKey) {
1315
- _context.next = 36;
1498
+ _context.next = 46;
1316
1499
  break;
1317
1500
  }
1318
1501
 
1319
- _context.next = 11;
1502
+ _context.next = 21;
1320
1503
  return fetch("".concat(process.env['FRONTEGG_BASE_URL'], "/frontegg").concat(fronteggRefreshTokenUrl), {
1321
1504
  method: 'POST',
1322
1505
  credentials: 'include',
@@ -1332,42 +1515,42 @@ function refreshToken(ctx) {
1332
1515
  }
1333
1516
  });
1334
1517
 
1335
- case 11:
1518
+ case 21:
1336
1519
  response = _context.sent;
1337
1520
 
1338
1521
  if (!response.ok) {
1339
- _context.next = 36;
1522
+ _context.next = 46;
1340
1523
  break;
1341
1524
  }
1342
1525
 
1343
- _context.next = 15;
1526
+ _context.next = 25;
1344
1527
  return response.text();
1345
1528
 
1346
- case 15:
1529
+ case 25:
1347
1530
  data = _context.sent;
1348
1531
  rewriteCookieDomainConfig = _defineProperty({}, fronteggConfig.baseUrlHost, fronteggConfig.cookieDomain); // @ts-ignore
1349
1532
 
1350
1533
  cookieHeader = response.headers.raw()['set-cookie'];
1351
1534
  newSetCookie = rewriteCookieProperty(cookieHeader, rewriteCookieDomainConfig, 'domain');
1352
- _context.next = 21;
1535
+ _context.next = 31;
1353
1536
  return createSessionFromAccessToken(data);
1354
1537
 
1355
- case 21:
1538
+ case 31:
1356
1539
  _yield$createSessionF = _context.sent;
1357
1540
  _yield$createSessionF2 = _slicedToArray(_yield$createSessionF, 2);
1358
- session = _yield$createSessionF2[0];
1541
+ _session = _yield$createSessionF2[0];
1359
1542
  decodedJwt = _yield$createSessionF2[1];
1360
1543
 
1361
- if (session) {
1362
- _context.next = 27;
1544
+ if (_session) {
1545
+ _context.next = 37;
1363
1546
  break;
1364
1547
  }
1365
1548
 
1366
1549
  return _context.abrupt("return", null);
1367
1550
 
1368
- case 27:
1551
+ case 37:
1369
1552
  isSecured = new URL(fronteggConfig.appUrl).protocol === 'https:';
1370
- cookieValue = cookie.serialize(fronteggConfig.cookieName, session, {
1553
+ cookieValue = cookie.serialize(fronteggConfig.cookieName, _session, {
1371
1554
  expires: new Date(decodedJwt.exp * 1000),
1372
1555
  httpOnly: true,
1373
1556
  domain: fronteggConfig.cookieDomain,
@@ -1391,21 +1574,21 @@ function refreshToken(ctx) {
1391
1574
  user: decodedJwt
1392
1575
  });
1393
1576
 
1394
- case 36:
1577
+ case 46:
1395
1578
  return _context.abrupt("return", null);
1396
1579
 
1397
- case 39:
1398
- _context.prev = 39;
1399
- _context.t0 = _context["catch"](0);
1400
- console.log(_context.t0);
1580
+ case 49:
1581
+ _context.prev = 49;
1582
+ _context.t1 = _context["catch"](0);
1583
+ console.log(_context.t1);
1401
1584
  return _context.abrupt("return", null);
1402
1585
 
1403
- case 43:
1586
+ case 53:
1404
1587
  case "end":
1405
1588
  return _context.stop();
1406
1589
  }
1407
1590
  }
1408
- }, _callee, null, [[0, 39]]);
1591
+ }, _callee, null, [[0, 49], [4, 12]]);
1409
1592
  }));
1410
1593
  }
1411
1594
  function addToCookies(cookieValue, res) {
@@ -1439,38 +1622,40 @@ function removeCookies(cookieName, isSecured, cookieDomain, res) {
1439
1622
  res.setHeader('set-cookie', [].concat(_toConsumableArray(existingSetCookie), [cookieValue]));
1440
1623
  }
1441
1624
  function createSessionFromAccessToken(output) {
1442
- return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
1443
- var _JSON$parse, accessToken, decodedJwt, session;
1625
+ var _a;
1444
1626
 
1627
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
1628
+ var data, accessToken, decodedJwt, session;
1445
1629
  return regenerator.wrap(function _callee2$(_context2) {
1446
1630
  while (1) {
1447
1631
  switch (_context2.prev = _context2.next) {
1448
1632
  case 0:
1449
1633
  _context2.prev = 0;
1450
- _JSON$parse = JSON.parse(output), accessToken = _JSON$parse.accessToken;
1634
+ data = JSON.parse(output);
1635
+ accessToken = (_a = data === null || data === void 0 ? void 0 : data.accessToken) !== null && _a !== void 0 ? _a : data.access_token;
1451
1636
  decodedJwt = decodeJwt(accessToken);
1452
1637
  decodedJwt.expiresIn = Math.floor((decodedJwt.exp * 1000 - Date.now()) / 1000);
1453
- _context2.next = 6;
1638
+ _context2.next = 7;
1454
1639
  return sealData(accessToken, {
1455
1640
  password: fronteggConfig.passwordsAsMap,
1456
1641
  ttl: decodedJwt.exp
1457
1642
  });
1458
1643
 
1459
- case 6:
1644
+ case 7:
1460
1645
  session = _context2.sent;
1461
1646
  return _context2.abrupt("return", [session, decodedJwt]);
1462
1647
 
1463
- case 10:
1464
- _context2.prev = 10;
1648
+ case 11:
1649
+ _context2.prev = 11;
1465
1650
  _context2.t0 = _context2["catch"](0);
1466
1651
  return _context2.abrupt("return", []);
1467
1652
 
1468
- case 13:
1653
+ case 14:
1469
1654
  case "end":
1470
1655
  return _context2.stop();
1471
1656
  }
1472
1657
  }
1473
- }, _callee2, null, [[0, 10]]);
1658
+ }, _callee2, null, [[0, 11]]);
1474
1659
  }));
1475
1660
  }
1476
1661
  var modifySetCookieIfUnsecure = function modifySetCookieIfUnsecure(setCookieValue, isSecured) {
@@ -1660,6 +1845,7 @@ var withFronteggApp = function withFronteggApp(app, options) {
1660
1845
  };
1661
1846
 
1662
1847
  fronteggConfig.authRoutes = (_b = (_a = options === null || options === void 0 ? void 0 : options.authOptions) === null || _a === void 0 ? void 0 : _a.routes) !== null && _b !== void 0 ? _b : {};
1848
+ fronteggConfig.fronteggAppOptions = options !== null && options !== void 0 ? options : {};
1663
1849
 
1664
1850
  function CustomFronteggApp(appProps) {
1665
1851
  return jsx(FronteggProvider, Object.assign({}, options, {
@@ -1676,114 +1862,6 @@ var withFronteggApp = function withFronteggApp(app, options) {
1676
1862
  return CustomFronteggApp;
1677
1863
  };
1678
1864
 
1679
- function getSession(req) {
1680
- return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
1681
- var sealFromCookies, jwt, publicKey, _yield$jwtVerify, payload, session;
1682
-
1683
- return regenerator.wrap(function _callee$(_context) {
1684
- while (1) {
1685
- switch (_context.prev = _context.next) {
1686
- case 0:
1687
- _context.prev = 0;
1688
- sealFromCookies = cookie.parse(req.headers.cookie || '')[fronteggConfig.cookieName];
1689
-
1690
- if (sealFromCookies) {
1691
- _context.next = 4;
1692
- break;
1693
- }
1694
-
1695
- return _context.abrupt("return", undefined);
1696
-
1697
- case 4:
1698
- _context.next = 6;
1699
- return unsealData(sealFromCookies, {
1700
- password: fronteggConfig.passwordsAsMap
1701
- });
1702
-
1703
- case 6:
1704
- jwt = _context.sent;
1705
- _context.next = 9;
1706
- return fronteggConfig.getJwtPublicKey();
1707
-
1708
- case 9:
1709
- publicKey = _context.sent;
1710
- _context.next = 12;
1711
- return jwtVerify(jwt, publicKey);
1712
-
1713
- case 12:
1714
- _yield$jwtVerify = _context.sent;
1715
- payload = _yield$jwtVerify.payload;
1716
- session = {
1717
- accessToken: jwt,
1718
- user: payload
1719
- };
1720
-
1721
- if (!(session.user.exp * 1000 < Date.now())) {
1722
- _context.next = 17;
1723
- break;
1724
- }
1725
-
1726
- return _context.abrupt("return", undefined);
1727
-
1728
- case 17:
1729
- return _context.abrupt("return", session);
1730
-
1731
- case 20:
1732
- _context.prev = 20;
1733
- _context.t0 = _context["catch"](0);
1734
- console.error(_context.t0);
1735
- return _context.abrupt("return", undefined);
1736
-
1737
- case 24:
1738
- case "end":
1739
- return _context.stop();
1740
- }
1741
- }
1742
- }, _callee, null, [[0, 20]]);
1743
- }));
1744
- }
1745
- function withSSRSession(handler) {
1746
- var _this = this;
1747
-
1748
- return function (context) {
1749
- return __awaiter(_this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
1750
- var session;
1751
- return regenerator.wrap(function _callee2$(_context2) {
1752
- while (1) {
1753
- switch (_context2.prev = _context2.next) {
1754
- case 0:
1755
- _context2.next = 2;
1756
- return getSession(context.req);
1757
-
1758
- case 2:
1759
- session = _context2.sent;
1760
-
1761
- if (!session) {
1762
- _context2.next = 7;
1763
- break;
1764
- }
1765
-
1766
- return _context2.abrupt("return", handler(context, session));
1767
-
1768
- case 7:
1769
- return _context2.abrupt("return", {
1770
- redirect: {
1771
- permanent: false,
1772
- destination: "/account/login?redirectUrl=".concat(encodeURIComponent(context.req.url))
1773
- },
1774
- props: {}
1775
- });
1776
-
1777
- case 8:
1778
- case "end":
1779
- return _context2.stop();
1780
- }
1781
- }
1782
- }, _callee2);
1783
- }));
1784
- };
1785
- }
1786
-
1787
1865
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
1788
1866
 
1789
1867
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@frontegg/nextjs",
3
- "version": "5.3.1-alpha.2448524672",
3
+ "version": "5.4.0-alpha.2494449312",
4
4
  "dependencies": {
5
- "@frontegg/admin-portal": "5.52.0",
6
- "@frontegg/react-hooks": "5.52.0",
5
+ "@frontegg/admin-portal": "5.54.2",
6
+ "@frontegg/react-hooks": "5.54.2",
7
7
  "jose": "^4.8.0",
8
8
  "iron-session": "^6.1.2",
9
9
  "http-proxy": "^1.18.1",