@frontegg/nextjs 5.3.0 → 5.4.0-alpha.2494518347
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 +214 -4
- package/index.cjs.js +230 -152
- package/index.esm.js +234 -156
- package/package.json +4 -4
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,
|
|
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 {
|
|
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
|
|
55
|
-
var _b;
|
|
54
|
+
var AppContext = /*#__PURE__*/createContext(null);
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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 = (
|
|
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.
|
|
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(
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
children: props
|
|
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,
|
|
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 =
|
|
1498
|
+
_context.next = 46;
|
|
1316
1499
|
break;
|
|
1317
1500
|
}
|
|
1318
1501
|
|
|
1319
|
-
_context.next =
|
|
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
|
|
1518
|
+
case 21:
|
|
1336
1519
|
response = _context.sent;
|
|
1337
1520
|
|
|
1338
1521
|
if (!response.ok) {
|
|
1339
|
-
_context.next =
|
|
1522
|
+
_context.next = 46;
|
|
1340
1523
|
break;
|
|
1341
1524
|
}
|
|
1342
1525
|
|
|
1343
|
-
_context.next =
|
|
1526
|
+
_context.next = 25;
|
|
1344
1527
|
return response.text();
|
|
1345
1528
|
|
|
1346
|
-
case
|
|
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 =
|
|
1535
|
+
_context.next = 31;
|
|
1353
1536
|
return createSessionFromAccessToken(data);
|
|
1354
1537
|
|
|
1355
|
-
case
|
|
1538
|
+
case 31:
|
|
1356
1539
|
_yield$createSessionF = _context.sent;
|
|
1357
1540
|
_yield$createSessionF2 = _slicedToArray(_yield$createSessionF, 2);
|
|
1358
|
-
|
|
1541
|
+
_session = _yield$createSessionF2[0];
|
|
1359
1542
|
decodedJwt = _yield$createSessionF2[1];
|
|
1360
1543
|
|
|
1361
|
-
if (
|
|
1362
|
-
_context.next =
|
|
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
|
|
1551
|
+
case 37:
|
|
1369
1552
|
isSecured = new URL(fronteggConfig.appUrl).protocol === 'https:';
|
|
1370
|
-
cookieValue = cookie.serialize(fronteggConfig.cookieName,
|
|
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
|
|
1577
|
+
case 46:
|
|
1395
1578
|
return _context.abrupt("return", null);
|
|
1396
1579
|
|
|
1397
|
-
case
|
|
1398
|
-
_context.prev =
|
|
1399
|
-
_context.
|
|
1400
|
-
console.log(_context.
|
|
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
|
|
1586
|
+
case 53:
|
|
1404
1587
|
case "end":
|
|
1405
1588
|
return _context.stop();
|
|
1406
1589
|
}
|
|
1407
1590
|
}
|
|
1408
|
-
}, _callee, null, [[0,
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
1644
|
+
case 7:
|
|
1460
1645
|
session = _context2.sent;
|
|
1461
1646
|
return _context2.abrupt("return", [session, decodedJwt]);
|
|
1462
1647
|
|
|
1463
|
-
case
|
|
1464
|
-
_context2.prev =
|
|
1648
|
+
case 11:
|
|
1649
|
+
_context2.prev = 11;
|
|
1465
1650
|
_context2.t0 = _context2["catch"](0);
|
|
1466
1651
|
return _context2.abrupt("return", []);
|
|
1467
1652
|
|
|
1468
|
-
case
|
|
1653
|
+
case 14:
|
|
1469
1654
|
case "end":
|
|
1470
1655
|
return _context2.stop();
|
|
1471
1656
|
}
|
|
1472
1657
|
}
|
|
1473
|
-
}, _callee2, null, [[0,
|
|
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
|
+
"version": "5.4.0-alpha.2494518347",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@frontegg/admin-portal": "5.
|
|
6
|
-
"@frontegg/react-hooks": "5.
|
|
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",
|
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
"main": "./index.cjs.js",
|
|
17
17
|
"module": "./index.esm.js",
|
|
18
18
|
"typings": "./index.d.ts"
|
|
19
|
-
}
|
|
19
|
+
}
|