@frontegg/nextjs 5.3.1-alpha.2448524672 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AppContext.d.ts +4 -0
- package/FronteggConfig.d.ts +2 -0
- package/README.md +4 -214
- package/index.cjs.js +230 -152
- package/index.esm.js +234 -156
- package/package.json +4 -4
package/index.cjs.js
CHANGED
|
@@ -58,15 +58,19 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
var
|
|
62
|
-
var _b;
|
|
61
|
+
var AppContext = /*#__PURE__*/react.createContext(null);
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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 = (
|
|
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.
|
|
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(
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
children: props
|
|
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,
|
|
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 =
|
|
1505
|
+
_context.next = 46;
|
|
1323
1506
|
break;
|
|
1324
1507
|
}
|
|
1325
1508
|
|
|
1326
|
-
_context.next =
|
|
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
|
|
1525
|
+
case 21:
|
|
1343
1526
|
response = _context.sent;
|
|
1344
1527
|
|
|
1345
1528
|
if (!response.ok) {
|
|
1346
|
-
_context.next =
|
|
1529
|
+
_context.next = 46;
|
|
1347
1530
|
break;
|
|
1348
1531
|
}
|
|
1349
1532
|
|
|
1350
|
-
_context.next =
|
|
1533
|
+
_context.next = 25;
|
|
1351
1534
|
return response.text();
|
|
1352
1535
|
|
|
1353
|
-
case
|
|
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 =
|
|
1542
|
+
_context.next = 31;
|
|
1360
1543
|
return createSessionFromAccessToken(data);
|
|
1361
1544
|
|
|
1362
|
-
case
|
|
1545
|
+
case 31:
|
|
1363
1546
|
_yield$createSessionF = _context.sent;
|
|
1364
1547
|
_yield$createSessionF2 = _slicedToArray(_yield$createSessionF, 2);
|
|
1365
|
-
|
|
1548
|
+
_session = _yield$createSessionF2[0];
|
|
1366
1549
|
decodedJwt = _yield$createSessionF2[1];
|
|
1367
1550
|
|
|
1368
|
-
if (
|
|
1369
|
-
_context.next =
|
|
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
|
|
1558
|
+
case 37:
|
|
1376
1559
|
isSecured = new URL(fronteggConfig.appUrl).protocol === 'https:';
|
|
1377
|
-
cookieValue = cookie__default["default"].serialize(fronteggConfig.cookieName,
|
|
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
|
|
1584
|
+
case 46:
|
|
1402
1585
|
return _context.abrupt("return", null);
|
|
1403
1586
|
|
|
1404
|
-
case
|
|
1405
|
-
_context.prev =
|
|
1406
|
-
_context.
|
|
1407
|
-
console.log(_context.
|
|
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
|
|
1593
|
+
case 53:
|
|
1411
1594
|
case "end":
|
|
1412
1595
|
return _context.stop();
|
|
1413
1596
|
}
|
|
1414
1597
|
}
|
|
1415
|
-
}, _callee, null, [[0,
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
1651
|
+
case 7:
|
|
1467
1652
|
session = _context2.sent;
|
|
1468
1653
|
return _context2.abrupt("return", [session, decodedJwt]);
|
|
1469
1654
|
|
|
1470
|
-
case
|
|
1471
|
-
_context2.prev =
|
|
1655
|
+
case 11:
|
|
1656
|
+
_context2.prev = 11;
|
|
1472
1657
|
_context2.t0 = _context2["catch"](0);
|
|
1473
1658
|
return _context2.abrupt("return", []);
|
|
1474
1659
|
|
|
1475
|
-
case
|
|
1660
|
+
case 14:
|
|
1476
1661
|
case "end":
|
|
1477
1662
|
return _context2.stop();
|
|
1478
1663
|
}
|
|
1479
1664
|
}
|
|
1480
|
-
}, _callee2, null, [[0,
|
|
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); }
|