@frontegg/nextjs 6.7.6-alpha.3627250069 → 6.7.6-alpha.3676548486
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/FronteggConfig.d.ts +2 -0
- package/FronteggProvider.d.ts +2 -2
- package/api.d.ts +3 -0
- package/consts.d.ts +5 -0
- package/helpers.d.ts +2 -1
- package/index.cjs.js +302 -72
- package/index.esm.js +304 -74
- package/package.json +3 -3
- package/types.d.ts +10 -0
package/FronteggConfig.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KeyLike } from 'jose';
|
|
2
2
|
import { AuthPageRoutes } from '@frontegg/redux-store';
|
|
3
3
|
import { FronteggAppOptions } from '@frontegg/types';
|
|
4
|
+
import { AppEnvConfig } from './types';
|
|
4
5
|
export declare type PasswordsMap = {
|
|
5
6
|
[id: string]: string;
|
|
6
7
|
};
|
|
@@ -21,6 +22,7 @@ declare class FronteggConfig {
|
|
|
21
22
|
get baseUrlHost(): string;
|
|
22
23
|
getEnvAppUrl(): string | undefined;
|
|
23
24
|
get appUrl(): string;
|
|
25
|
+
get appEnvConfig(): AppEnvConfig;
|
|
24
26
|
get cookieDomain(): string;
|
|
25
27
|
getJwtPublicKey(): Promise<KeyLike | Uint8Array>;
|
|
26
28
|
get passwordsAsMap(): PasswordsMap;
|
package/FronteggProvider.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FC, ReactNode } from 'react';
|
|
2
2
|
import { FronteggAppOptions } from '@frontegg/types';
|
|
3
|
-
import { FronteggNextJSSession } from './types';
|
|
4
|
-
export declare type FronteggProviderProps = Omit<FronteggAppOptions, 'contextOptions'> & {
|
|
3
|
+
import { MeAndTenants, FronteggNextJSSession } from './types';
|
|
4
|
+
export declare type FronteggProviderProps = Omit<FronteggAppOptions, 'contextOptions'> & MeAndTenants & {
|
|
5
5
|
children?: ReactNode;
|
|
6
6
|
session?: FronteggNextJSSession;
|
|
7
7
|
envAppUrl: string;
|
package/api.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ILoginResponse, ITenantsResponse } from '@frontegg/rest-api';
|
|
2
|
+
export declare const getUsers: (headers: Record<string, string>) => Promise<ILoginResponse | undefined>;
|
|
3
|
+
export declare const getTenants: (headers: Record<string, string>) => Promise<ITenantsResponse[] | undefined>;
|
package/consts.d.ts
ADDED
package/helpers.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ServerResponse } from 'http';
|
|
3
3
|
import { CookieSerializeOptions } from 'cookie';
|
|
4
4
|
import { NextPageContext } from 'next/dist/shared/lib/utils';
|
|
5
|
-
import { FronteggNextJSSession } from './types';
|
|
5
|
+
import { FronteggNextJSSession, MeAndTenants } from './types';
|
|
6
6
|
export declare function refreshToken(ctx: NextPageContext): Promise<FronteggNextJSSession | null>;
|
|
7
7
|
declare type CreateCookieArguments = {
|
|
8
8
|
cookieName?: string;
|
|
@@ -21,4 +21,5 @@ export declare function compress(input: string): Promise<string>;
|
|
|
21
21
|
export declare function uncompress(input: string): Promise<string>;
|
|
22
22
|
export declare function createSessionFromAccessToken(output: string): Promise<[string, any, string] | []>;
|
|
23
23
|
export declare const modifySetCookieIfUnsecure: (setCookieValue: string[] | undefined, isSecured: boolean) => string[] | undefined;
|
|
24
|
+
export declare function meAndTenants(ctx: NextPageContext, accessToken?: string): Promise<MeAndTenants>;
|
|
24
25
|
export {};
|
package/index.cjs.js
CHANGED
|
@@ -5,11 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var react = require('react');
|
|
7
7
|
var js = require('@frontegg/js');
|
|
8
|
+
var reduxStore = require('@frontegg/redux-store');
|
|
8
9
|
var reactHooks = require('@frontegg/react-hooks');
|
|
9
10
|
var restApi = require('@frontegg/rest-api');
|
|
10
11
|
var router = require('next/router');
|
|
11
12
|
var jose = require('jose');
|
|
12
|
-
var reduxStore = require('@frontegg/redux-store');
|
|
13
13
|
var url = require('url');
|
|
14
14
|
var cookie = require('cookie');
|
|
15
15
|
var ironSession = require('iron-session');
|
|
@@ -80,17 +80,25 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
80
80
|
|
|
81
81
|
var AppContext = /*#__PURE__*/react.createContext(null);
|
|
82
82
|
|
|
83
|
-
var Connector$1 = function Connector(
|
|
84
|
-
var
|
|
83
|
+
var Connector$1 = function Connector(_a) {
|
|
84
|
+
var _b;
|
|
85
85
|
|
|
86
|
-
var router =
|
|
87
|
-
appName =
|
|
88
|
-
hostedLoginBox =
|
|
89
|
-
customLoginBox =
|
|
90
|
-
|
|
86
|
+
var router = _a.router,
|
|
87
|
+
appName = _a.appName,
|
|
88
|
+
hostedLoginBox = _a.hostedLoginBox,
|
|
89
|
+
customLoginBox = _a.customLoginBox,
|
|
90
|
+
user = _a.user,
|
|
91
|
+
tenants = _a.tenants,
|
|
92
|
+
session = _a.session,
|
|
93
|
+
props = __rest(_a, ["router", "appName", "hostedLoginBox", "customLoginBox", "user", "tenants", "session"]);
|
|
94
|
+
|
|
95
|
+
var _ref = session !== null && session !== void 0 ? session : {},
|
|
96
|
+
accessToken = _ref.accessToken,
|
|
97
|
+
refreshToken = _ref.refreshToken;
|
|
91
98
|
|
|
92
99
|
var isSSR = typeof window === 'undefined';
|
|
93
|
-
var
|
|
100
|
+
var storeHolder = react.useRef({});
|
|
101
|
+
var baseName = (_b = props.basename) !== null && _b !== void 0 ? _b : router.basePath;
|
|
94
102
|
var onRedirectTo = react.useCallback(function (_path, opts) {
|
|
95
103
|
var path = _path;
|
|
96
104
|
|
|
@@ -110,7 +118,9 @@ var Connector$1 = function Connector(_props) {
|
|
|
110
118
|
}
|
|
111
119
|
}, []);
|
|
112
120
|
var contextOptions = react.useMemo(function () {
|
|
113
|
-
return {
|
|
121
|
+
return Object.assign(Object.assign({
|
|
122
|
+
requestCredentials: 'include'
|
|
123
|
+
}, props.contextOptions), {
|
|
114
124
|
baseUrl: function baseUrl(path) {
|
|
115
125
|
if (restApi.fronteggAuthApiRoutes.indexOf(path) !== -1 || path.endsWith('/postlogin') || path.endsWith('/prelogin') || path === '/oauth/token') {
|
|
116
126
|
return "".concat(props.envAppUrl, "/api");
|
|
@@ -119,8 +129,41 @@ var Connector$1 = function Connector(_props) {
|
|
|
119
129
|
}
|
|
120
130
|
},
|
|
121
131
|
clientId: props.envClientId
|
|
122
|
-
};
|
|
123
|
-
}, [props.envAppUrl, props.envBaseUrl, props.envClientId]);
|
|
132
|
+
});
|
|
133
|
+
}, [props.envAppUrl, props.envBaseUrl, props.envClientId, props.contextOptions]);
|
|
134
|
+
var authOptions = react.useMemo(function () {
|
|
135
|
+
var _a, _b, _c, _d;
|
|
136
|
+
|
|
137
|
+
var tenantsState = tenants ? Object.assign({
|
|
138
|
+
tenantTree: null,
|
|
139
|
+
subTenants: [],
|
|
140
|
+
tenants: tenants,
|
|
141
|
+
loading: false
|
|
142
|
+
}, (_a = props.authOptions) === null || _a === void 0 ? void 0 : _a.tenantsState) : undefined;
|
|
143
|
+
var userData = user ? Object.assign(Object.assign(Object.assign({}, user), {
|
|
144
|
+
accessToken: accessToken !== null && accessToken !== void 0 ? accessToken : '',
|
|
145
|
+
refreshToken: refreshToken !== null && refreshToken !== void 0 ? refreshToken : undefined
|
|
146
|
+
}), (_b = props.authOptions) === null || _b === void 0 ? void 0 : _b.user) : null;
|
|
147
|
+
return Object.assign(Object.assign({}, props.authOptions), {
|
|
148
|
+
onRedirectTo: onRedirectTo,
|
|
149
|
+
isLoading: false,
|
|
150
|
+
isAuthenticated: !!session,
|
|
151
|
+
hostedLoginBox: hostedLoginBox !== null && hostedLoginBox !== void 0 ? hostedLoginBox : false,
|
|
152
|
+
disableSilentRefresh: (_d = (_c = props.authOptions) === null || _c === void 0 ? void 0 : _c.disableSilentRefresh) !== null && _d !== void 0 ? _d : false,
|
|
153
|
+
user: userData,
|
|
154
|
+
tenantsState: tenantsState
|
|
155
|
+
});
|
|
156
|
+
}, [accessToken, hostedLoginBox, onRedirectTo, props.authOptions, refreshToken, session, tenants, user]);
|
|
157
|
+
var sharedStore = react.useMemo(function () {
|
|
158
|
+
var _a;
|
|
159
|
+
|
|
160
|
+
return reduxStore.createFronteggStore({
|
|
161
|
+
context: contextOptions
|
|
162
|
+
}, storeHolder.current, props.previewMode, authOptions, {
|
|
163
|
+
auth: authOptions !== null && authOptions !== void 0 ? authOptions : {},
|
|
164
|
+
audits: (_a = props.auditsOptions) !== null && _a !== void 0 ? _a : {}
|
|
165
|
+
}, false, props.urlStrategy);
|
|
166
|
+
}, [authOptions, contextOptions, props.auditsOptions, props.previewMode, props.urlStrategy]);
|
|
124
167
|
var app = react.useMemo(function () {
|
|
125
168
|
var _a;
|
|
126
169
|
|
|
@@ -128,34 +171,31 @@ var Connector$1 = function Connector(_props) {
|
|
|
128
171
|
|
|
129
172
|
try {
|
|
130
173
|
createdApp = js.AppHolder.getInstance(appName !== null && appName !== void 0 ? appName : 'default');
|
|
174
|
+
createdApp.store = sharedStore;
|
|
131
175
|
} catch (e) {
|
|
132
176
|
createdApp = js.initialize(Object.assign(Object.assign({}, props), {
|
|
177
|
+
store: sharedStore,
|
|
133
178
|
hostedLoginBox: hostedLoginBox !== null && hostedLoginBox !== void 0 ? hostedLoginBox : false,
|
|
134
179
|
customLoginBox: customLoginBox !== null && customLoginBox !== void 0 ? customLoginBox : false,
|
|
135
180
|
basename: (_a = props.basename) !== null && _a !== void 0 ? _a : baseName,
|
|
136
|
-
authOptions:
|
|
137
|
-
|
|
138
|
-
}),
|
|
139
|
-
contextOptions: Object.assign(Object.assign({
|
|
140
|
-
requestCredentials: 'include'
|
|
141
|
-
}, props.contextOptions), contextOptions),
|
|
181
|
+
authOptions: authOptions,
|
|
182
|
+
contextOptions: contextOptions,
|
|
142
183
|
onRedirectTo: onRedirectTo
|
|
143
184
|
}), appName !== null && appName !== void 0 ? appName : 'default');
|
|
144
185
|
}
|
|
145
186
|
|
|
146
187
|
return createdApp;
|
|
147
|
-
}, [appName, props, hostedLoginBox, baseName, onRedirectTo, contextOptions]);
|
|
188
|
+
}, [appName, props, hostedLoginBox, baseName, onRedirectTo, contextOptions, customLoginBox, authOptions, sharedStore]);
|
|
148
189
|
restApi.ContextHolder.setOnRedirectTo(onRedirectTo);
|
|
149
190
|
react.useEffect(function () {
|
|
150
|
-
|
|
151
|
-
// @ts-ignore
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
app.store.dispatch({
|
|
191
|
+
app === null || app === void 0 ? void 0 : app.store.dispatch({
|
|
155
192
|
type: 'auth/requestAuthorizeSSR',
|
|
156
|
-
payload:
|
|
157
|
-
|
|
158
|
-
|
|
193
|
+
payload: {
|
|
194
|
+
accessToken: accessToken,
|
|
195
|
+
user: user ? Object.assign(Object.assign({}, user), {
|
|
196
|
+
refreshToken: refreshToken
|
|
197
|
+
}) : null,
|
|
198
|
+
tenants: tenants
|
|
159
199
|
}
|
|
160
200
|
});
|
|
161
201
|
}, [app]);
|
|
@@ -1239,6 +1279,15 @@ var FronteggConfig = /*#__PURE__*/function () {
|
|
|
1239
1279
|
|
|
1240
1280
|
return (_a = this.getEnvAppUrl()) !== null && _a !== void 0 ? _a : 'http://localhost:3000';
|
|
1241
1281
|
}
|
|
1282
|
+
}, {
|
|
1283
|
+
key: "appEnvConfig",
|
|
1284
|
+
get: function get() {
|
|
1285
|
+
return {
|
|
1286
|
+
envAppUrl: this.getEnvAppUrl(),
|
|
1287
|
+
envBaseUrl: process.env['FRONTEGG_BASE_URL'],
|
|
1288
|
+
envClientId: process.env['FRONTEGG_CLIENT_ID']
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1242
1291
|
}, {
|
|
1243
1292
|
key: "cookieDomain",
|
|
1244
1293
|
get: function get() {
|
|
@@ -1652,6 +1701,115 @@ function withSSRSession(handler) {
|
|
|
1652
1701
|
};
|
|
1653
1702
|
}
|
|
1654
1703
|
|
|
1704
|
+
var BASE_URL = "".concat(process.env['FRONTEGG_BASE_URL'], "/frontegg");
|
|
1705
|
+
|
|
1706
|
+
var Get = function Get(_ref) {
|
|
1707
|
+
var url = _ref.url,
|
|
1708
|
+
_ref$credentials = _ref.credentials,
|
|
1709
|
+
credentials = _ref$credentials === void 0 ? 'include' : _ref$credentials,
|
|
1710
|
+
headers = _ref.headers;
|
|
1711
|
+
return fetch(url, {
|
|
1712
|
+
method: 'GET',
|
|
1713
|
+
credentials: credentials,
|
|
1714
|
+
headers: headers
|
|
1715
|
+
});
|
|
1716
|
+
};
|
|
1717
|
+
|
|
1718
|
+
var extractHeaders = function extractHeaders(headers) {
|
|
1719
|
+
return {
|
|
1720
|
+
'accept-encoding': headers['accept-encoding'],
|
|
1721
|
+
'accept-language': headers['accept-language'],
|
|
1722
|
+
cookie: headers['cookie'],
|
|
1723
|
+
accept: headers['accept'],
|
|
1724
|
+
'user-agent': headers['user-agent'],
|
|
1725
|
+
connection: headers['connection'],
|
|
1726
|
+
'cache-control': headers['cache-control'],
|
|
1727
|
+
'Authorization': headers['Authorization']
|
|
1728
|
+
};
|
|
1729
|
+
};
|
|
1730
|
+
|
|
1731
|
+
var parseResponse = function parseResponse(res) {
|
|
1732
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
1733
|
+
var resText;
|
|
1734
|
+
return regenerator.wrap(function _callee$(_context) {
|
|
1735
|
+
while (1) {
|
|
1736
|
+
switch (_context.prev = _context.next) {
|
|
1737
|
+
case 0:
|
|
1738
|
+
if (res.ok) {
|
|
1739
|
+
_context.next = 2;
|
|
1740
|
+
break;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
return _context.abrupt("return", undefined);
|
|
1744
|
+
|
|
1745
|
+
case 2:
|
|
1746
|
+
_context.next = 4;
|
|
1747
|
+
return res.text();
|
|
1748
|
+
|
|
1749
|
+
case 4:
|
|
1750
|
+
resText = _context.sent;
|
|
1751
|
+
return _context.abrupt("return", JSON.parse(resText));
|
|
1752
|
+
|
|
1753
|
+
case 6:
|
|
1754
|
+
case "end":
|
|
1755
|
+
return _context.stop();
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
}, _callee);
|
|
1759
|
+
}));
|
|
1760
|
+
};
|
|
1761
|
+
|
|
1762
|
+
var getUsers = function getUsers(headers) {
|
|
1763
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
|
|
1764
|
+
var res;
|
|
1765
|
+
return regenerator.wrap(function _callee2$(_context2) {
|
|
1766
|
+
while (1) {
|
|
1767
|
+
switch (_context2.prev = _context2.next) {
|
|
1768
|
+
case 0:
|
|
1769
|
+
_context2.next = 2;
|
|
1770
|
+
return Get({
|
|
1771
|
+
url: "".concat(BASE_URL).concat(restApi.fronteggUsersUrl),
|
|
1772
|
+
headers: extractHeaders(headers)
|
|
1773
|
+
});
|
|
1774
|
+
|
|
1775
|
+
case 2:
|
|
1776
|
+
res = _context2.sent;
|
|
1777
|
+
return _context2.abrupt("return", parseResponse(res));
|
|
1778
|
+
|
|
1779
|
+
case 4:
|
|
1780
|
+
case "end":
|
|
1781
|
+
return _context2.stop();
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
}, _callee2);
|
|
1785
|
+
}));
|
|
1786
|
+
};
|
|
1787
|
+
var getTenants = function getTenants(headers) {
|
|
1788
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
|
|
1789
|
+
var res;
|
|
1790
|
+
return regenerator.wrap(function _callee3$(_context3) {
|
|
1791
|
+
while (1) {
|
|
1792
|
+
switch (_context3.prev = _context3.next) {
|
|
1793
|
+
case 0:
|
|
1794
|
+
_context3.next = 2;
|
|
1795
|
+
return Get({
|
|
1796
|
+
url: "".concat(BASE_URL).concat(restApi.fronteggTenantsUrl),
|
|
1797
|
+
headers: extractHeaders(headers)
|
|
1798
|
+
});
|
|
1799
|
+
|
|
1800
|
+
case 2:
|
|
1801
|
+
res = _context3.sent;
|
|
1802
|
+
return _context3.abrupt("return", parseResponse(res));
|
|
1803
|
+
|
|
1804
|
+
case 4:
|
|
1805
|
+
case "end":
|
|
1806
|
+
return _context3.stop();
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
}, _callee3);
|
|
1810
|
+
}));
|
|
1811
|
+
};
|
|
1812
|
+
|
|
1655
1813
|
function rewriteCookieProperty(header, config, property) {
|
|
1656
1814
|
if (Array.isArray(header)) {
|
|
1657
1815
|
return header.map(function (headerElement) {
|
|
@@ -2128,6 +2286,58 @@ var modifySetCookieIfUnsecure = function modifySetCookieIfUnsecure(setCookieValu
|
|
|
2128
2286
|
|
|
2129
2287
|
return setCookieValue;
|
|
2130
2288
|
};
|
|
2289
|
+
function meAndTenants(ctx, accessToken) {
|
|
2290
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee5() {
|
|
2291
|
+
var request, headers, _yield$Promise$all, _yield$Promise$all2, user, tenants;
|
|
2292
|
+
|
|
2293
|
+
return regenerator.wrap(function _callee5$(_context5) {
|
|
2294
|
+
while (1) {
|
|
2295
|
+
switch (_context5.prev = _context5.next) {
|
|
2296
|
+
case 0:
|
|
2297
|
+
request = ctx.req;
|
|
2298
|
+
|
|
2299
|
+
if (!(!request || !accessToken)) {
|
|
2300
|
+
_context5.next = 3;
|
|
2301
|
+
break;
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
return _context5.abrupt("return", {});
|
|
2305
|
+
|
|
2306
|
+
case 3:
|
|
2307
|
+
headers = Object.assign(Object.assign({}, request.headers), {
|
|
2308
|
+
Authorization: "Bearer ".concat(accessToken)
|
|
2309
|
+
});
|
|
2310
|
+
_context5.next = 6;
|
|
2311
|
+
return Promise.all([getUsers(headers), getTenants(headers)]);
|
|
2312
|
+
|
|
2313
|
+
case 6:
|
|
2314
|
+
_yield$Promise$all = _context5.sent;
|
|
2315
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
2316
|
+
user = _yield$Promise$all2[0];
|
|
2317
|
+
tenants = _yield$Promise$all2[1];
|
|
2318
|
+
return _context5.abrupt("return", {
|
|
2319
|
+
user: user,
|
|
2320
|
+
tenants: tenants
|
|
2321
|
+
});
|
|
2322
|
+
|
|
2323
|
+
case 11:
|
|
2324
|
+
case "end":
|
|
2325
|
+
return _context5.stop();
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
}, _callee5);
|
|
2329
|
+
}));
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
var envError = function envError(varName) {
|
|
2333
|
+
return "@frontegg/nextjs: .env.local must contain ".concat(varName);
|
|
2334
|
+
};
|
|
2335
|
+
|
|
2336
|
+
var fronteggErrors = {
|
|
2337
|
+
envAppUrl: envError('FRONTEGG_APP_URL'),
|
|
2338
|
+
envBaseUrl: envError('FRONTEGG_BASE_URL'),
|
|
2339
|
+
envClientId: envError('FRONTEGG_CLIENT_ID')
|
|
2340
|
+
};
|
|
2131
2341
|
|
|
2132
2342
|
var withFronteggApp = function withFronteggApp(app, options) {
|
|
2133
2343
|
var _a, _b;
|
|
@@ -2136,7 +2346,7 @@ var withFronteggApp = function withFronteggApp(app, options) {
|
|
|
2136
2346
|
|
|
2137
2347
|
app.getInitialProps = function (appContext) {
|
|
2138
2348
|
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
2139
|
-
var
|
|
2349
|
+
var ctx, Component, session, _yield$meAndTenants, user, tenants, _fronteggConfig$appEn, envAppUrl, envBaseUrl, envClientId;
|
|
2140
2350
|
|
|
2141
2351
|
return regenerator.wrap(function _callee$(_context) {
|
|
2142
2352
|
while (1) {
|
|
@@ -2144,8 +2354,8 @@ var withFronteggApp = function withFronteggApp(app, options) {
|
|
|
2144
2354
|
case 0:
|
|
2145
2355
|
ctx = appContext.ctx, Component = appContext.Component;
|
|
2146
2356
|
|
|
2147
|
-
if (!
|
|
2148
|
-
_context.next =
|
|
2357
|
+
if (!ctx.req) {
|
|
2358
|
+
_context.next = 47;
|
|
2149
2359
|
break;
|
|
2150
2360
|
}
|
|
2151
2361
|
|
|
@@ -2154,79 +2364,90 @@ var withFronteggApp = function withFronteggApp(app, options) {
|
|
|
2154
2364
|
|
|
2155
2365
|
case 4:
|
|
2156
2366
|
session = _context.sent;
|
|
2367
|
+
_context.next = 7;
|
|
2368
|
+
return meAndTenants(ctx, session === null || session === void 0 ? void 0 : session.accessToken);
|
|
2369
|
+
|
|
2370
|
+
case 7:
|
|
2371
|
+
_yield$meAndTenants = _context.sent;
|
|
2372
|
+
user = _yield$meAndTenants.user;
|
|
2373
|
+
tenants = _yield$meAndTenants.tenants;
|
|
2157
2374
|
appContext.session = session;
|
|
2158
|
-
|
|
2375
|
+
appContext.user = user;
|
|
2376
|
+
appContext.tenants = tenants;
|
|
2377
|
+
_fronteggConfig$appEn = fronteggConfig.appEnvConfig, envAppUrl = _fronteggConfig$appEn.envAppUrl, envBaseUrl = _fronteggConfig$appEn.envBaseUrl, envClientId = _fronteggConfig$appEn.envClientId;
|
|
2159
2378
|
|
|
2160
2379
|
if (envAppUrl) {
|
|
2161
|
-
_context.next =
|
|
2380
|
+
_context.next = 16;
|
|
2162
2381
|
break;
|
|
2163
2382
|
}
|
|
2164
2383
|
|
|
2165
|
-
throw Error(
|
|
2384
|
+
throw Error(fronteggErrors.envAppUrl);
|
|
2166
2385
|
|
|
2167
|
-
case
|
|
2168
|
-
if (
|
|
2169
|
-
_context.next =
|
|
2386
|
+
case 16:
|
|
2387
|
+
if (envBaseUrl) {
|
|
2388
|
+
_context.next = 18;
|
|
2170
2389
|
break;
|
|
2171
2390
|
}
|
|
2172
2391
|
|
|
2173
|
-
throw Error(
|
|
2392
|
+
throw Error(fronteggErrors.envBaseUrl);
|
|
2174
2393
|
|
|
2175
|
-
case
|
|
2176
|
-
if (
|
|
2177
|
-
_context.next =
|
|
2394
|
+
case 18:
|
|
2395
|
+
if (envClientId) {
|
|
2396
|
+
_context.next = 20;
|
|
2178
2397
|
break;
|
|
2179
2398
|
}
|
|
2180
2399
|
|
|
2181
|
-
throw Error(
|
|
2400
|
+
throw Error(fronteggErrors.envClientId);
|
|
2182
2401
|
|
|
2183
|
-
case
|
|
2402
|
+
case 20:
|
|
2184
2403
|
_context.t0 = Object;
|
|
2185
2404
|
_context.t1 = Object;
|
|
2186
2405
|
_context.t2 = Object;
|
|
2187
2406
|
_context.t3 = {};
|
|
2188
2407
|
|
|
2189
2408
|
if (!originalGetInitialProps) {
|
|
2190
|
-
_context.next =
|
|
2409
|
+
_context.next = 30;
|
|
2191
2410
|
break;
|
|
2192
2411
|
}
|
|
2193
2412
|
|
|
2194
|
-
_context.next =
|
|
2413
|
+
_context.next = 27;
|
|
2195
2414
|
return originalGetInitialProps(appContext);
|
|
2196
2415
|
|
|
2197
|
-
case
|
|
2416
|
+
case 27:
|
|
2198
2417
|
_context.t4 = _context.sent;
|
|
2199
|
-
_context.next =
|
|
2418
|
+
_context.next = 31;
|
|
2200
2419
|
break;
|
|
2201
2420
|
|
|
2202
|
-
case
|
|
2421
|
+
case 30:
|
|
2203
2422
|
_context.t4 = {};
|
|
2204
2423
|
|
|
2205
|
-
case
|
|
2424
|
+
case 31:
|
|
2206
2425
|
_context.t5 = _context.t4;
|
|
2207
2426
|
_context.t6 = _context.t2.assign.call(_context.t2, _context.t3, _context.t5);
|
|
2208
2427
|
|
|
2209
2428
|
if (!Component.getInitialProps) {
|
|
2210
|
-
_context.next =
|
|
2429
|
+
_context.next = 39;
|
|
2211
2430
|
break;
|
|
2212
2431
|
}
|
|
2213
2432
|
|
|
2214
|
-
_context.next =
|
|
2433
|
+
_context.next = 36;
|
|
2215
2434
|
return Component.getInitialProps(ctx);
|
|
2216
2435
|
|
|
2217
|
-
case
|
|
2436
|
+
case 36:
|
|
2218
2437
|
_context.t7 = _context.sent;
|
|
2219
|
-
_context.next =
|
|
2438
|
+
_context.next = 40;
|
|
2220
2439
|
break;
|
|
2221
2440
|
|
|
2222
|
-
case
|
|
2441
|
+
case 39:
|
|
2223
2442
|
_context.t7 = {};
|
|
2224
2443
|
|
|
2225
|
-
case
|
|
2444
|
+
case 40:
|
|
2226
2445
|
_context.t8 = _context.t7;
|
|
2227
2446
|
_context.t9 = _context.t1.assign.call(_context.t1, _context.t6, _context.t8);
|
|
2228
2447
|
_context.t10 = {
|
|
2229
2448
|
session: session,
|
|
2449
|
+
user: user,
|
|
2450
|
+
tenants: tenants,
|
|
2230
2451
|
envAppUrl: envAppUrl,
|
|
2231
2452
|
envBaseUrl: process.env['FRONTEGG_BASE_URL'],
|
|
2232
2453
|
envClientId: process.env['FRONTEGG_CLIENT_ID']
|
|
@@ -2236,56 +2457,56 @@ var withFronteggApp = function withFronteggApp(app, options) {
|
|
|
2236
2457
|
pageProps: _context.t11
|
|
2237
2458
|
});
|
|
2238
2459
|
|
|
2239
|
-
case
|
|
2460
|
+
case 47:
|
|
2240
2461
|
appContext.session = null;
|
|
2241
2462
|
_context.t12 = Object;
|
|
2242
2463
|
_context.t13 = Object;
|
|
2243
2464
|
_context.t14 = {};
|
|
2244
2465
|
|
|
2245
2466
|
if (!originalGetInitialProps) {
|
|
2246
|
-
_context.next =
|
|
2467
|
+
_context.next = 57;
|
|
2247
2468
|
break;
|
|
2248
2469
|
}
|
|
2249
2470
|
|
|
2250
|
-
_context.next =
|
|
2471
|
+
_context.next = 54;
|
|
2251
2472
|
return originalGetInitialProps(appContext);
|
|
2252
2473
|
|
|
2253
|
-
case
|
|
2474
|
+
case 54:
|
|
2254
2475
|
_context.t15 = _context.sent;
|
|
2255
|
-
_context.next =
|
|
2476
|
+
_context.next = 58;
|
|
2256
2477
|
break;
|
|
2257
2478
|
|
|
2258
|
-
case
|
|
2479
|
+
case 57:
|
|
2259
2480
|
_context.t15 = {};
|
|
2260
2481
|
|
|
2261
|
-
case
|
|
2482
|
+
case 58:
|
|
2262
2483
|
_context.t16 = _context.t15;
|
|
2263
2484
|
_context.t17 = _context.t13.assign.call(_context.t13, _context.t14, _context.t16);
|
|
2264
2485
|
|
|
2265
2486
|
if (!Component.getInitialProps) {
|
|
2266
|
-
_context.next =
|
|
2487
|
+
_context.next = 66;
|
|
2267
2488
|
break;
|
|
2268
2489
|
}
|
|
2269
2490
|
|
|
2270
|
-
_context.next =
|
|
2491
|
+
_context.next = 63;
|
|
2271
2492
|
return Component.getInitialProps(ctx);
|
|
2272
2493
|
|
|
2273
|
-
case
|
|
2494
|
+
case 63:
|
|
2274
2495
|
_context.t18 = _context.sent;
|
|
2275
|
-
_context.next =
|
|
2496
|
+
_context.next = 67;
|
|
2276
2497
|
break;
|
|
2277
2498
|
|
|
2278
|
-
case
|
|
2499
|
+
case 66:
|
|
2279
2500
|
_context.t18 = {};
|
|
2280
2501
|
|
|
2281
|
-
case
|
|
2502
|
+
case 67:
|
|
2282
2503
|
_context.t19 = _context.t18;
|
|
2283
2504
|
_context.t20 = _context.t12.assign.call(_context.t12, _context.t17, _context.t19);
|
|
2284
2505
|
return _context.abrupt("return", {
|
|
2285
2506
|
pageProps: _context.t20
|
|
2286
2507
|
});
|
|
2287
2508
|
|
|
2288
|
-
case
|
|
2509
|
+
case 70:
|
|
2289
2510
|
case "end":
|
|
2290
2511
|
return _context.stop();
|
|
2291
2512
|
}
|
|
@@ -2298,11 +2519,20 @@ var withFronteggApp = function withFronteggApp(app, options) {
|
|
|
2298
2519
|
fronteggConfig.fronteggAppOptions = options !== null && options !== void 0 ? options : {};
|
|
2299
2520
|
|
|
2300
2521
|
function CustomFronteggApp(appProps) {
|
|
2522
|
+
var _appProps$pageProps = appProps.pageProps,
|
|
2523
|
+
user = _appProps$pageProps.user,
|
|
2524
|
+
tenants = _appProps$pageProps.tenants,
|
|
2525
|
+
session = _appProps$pageProps.session,
|
|
2526
|
+
envAppUrl = _appProps$pageProps.envAppUrl,
|
|
2527
|
+
envBaseUrl = _appProps$pageProps.envBaseUrl,
|
|
2528
|
+
envClientId = _appProps$pageProps.envClientId;
|
|
2301
2529
|
return jsxRuntime.jsx(FronteggProvider, Object.assign({}, options, {
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2530
|
+
user: user,
|
|
2531
|
+
tenants: tenants,
|
|
2532
|
+
session: session,
|
|
2533
|
+
envAppUrl: envAppUrl,
|
|
2534
|
+
envBaseUrl: envBaseUrl,
|
|
2535
|
+
envClientId: envClientId
|
|
2306
2536
|
}, {
|
|
2307
2537
|
children: app(appProps)
|
|
2308
2538
|
}));
|
package/index.esm.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { createContext, useCallback, useMemo, useEffect, useContext } from 'react';
|
|
2
|
+
import { createContext, useRef, useCallback, useMemo, useEffect, useContext } from 'react';
|
|
3
3
|
import { AppHolder, initialize } from '@frontegg/js';
|
|
4
4
|
export { AdminPortal } from '@frontegg/js';
|
|
5
|
+
import { createFronteggStore, authInitialState } from '@frontegg/redux-store';
|
|
5
6
|
import { FronteggStoreProvider, useAuthUserOrNull, useAuthActions, useLoginWithRedirect, useLoginActions } from '@frontegg/react-hooks';
|
|
6
7
|
export * from '@frontegg/react-hooks';
|
|
7
|
-
import { fronteggAuthApiRoutes, ContextHolder, fronteggRefreshTokenUrl, fronteggSilentRefreshTokenUrl } from '@frontegg/rest-api';
|
|
8
|
+
import { fronteggAuthApiRoutes, ContextHolder, fronteggUsersUrl, fronteggTenantsUrl, fronteggRefreshTokenUrl, fronteggSilentRefreshTokenUrl } from '@frontegg/rest-api';
|
|
8
9
|
export { ContextHolder } from '@frontegg/rest-api';
|
|
9
10
|
import { useRouter } from 'next/router';
|
|
10
11
|
import { importJWK, jwtVerify, decodeJwt } from 'jose';
|
|
11
|
-
import { authInitialState } from '@frontegg/redux-store';
|
|
12
12
|
import { parse } from 'url';
|
|
13
13
|
import cookie from 'cookie';
|
|
14
14
|
import { unsealData, sealData } from 'iron-session';
|
|
@@ -55,17 +55,25 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
55
55
|
|
|
56
56
|
var AppContext = /*#__PURE__*/createContext(null);
|
|
57
57
|
|
|
58
|
-
var Connector$1 = function Connector(
|
|
59
|
-
var
|
|
58
|
+
var Connector$1 = function Connector(_a) {
|
|
59
|
+
var _b;
|
|
60
60
|
|
|
61
|
-
var router =
|
|
62
|
-
appName =
|
|
63
|
-
hostedLoginBox =
|
|
64
|
-
customLoginBox =
|
|
65
|
-
|
|
61
|
+
var router = _a.router,
|
|
62
|
+
appName = _a.appName,
|
|
63
|
+
hostedLoginBox = _a.hostedLoginBox,
|
|
64
|
+
customLoginBox = _a.customLoginBox,
|
|
65
|
+
user = _a.user,
|
|
66
|
+
tenants = _a.tenants,
|
|
67
|
+
session = _a.session,
|
|
68
|
+
props = __rest(_a, ["router", "appName", "hostedLoginBox", "customLoginBox", "user", "tenants", "session"]);
|
|
69
|
+
|
|
70
|
+
var _ref = session !== null && session !== void 0 ? session : {},
|
|
71
|
+
accessToken = _ref.accessToken,
|
|
72
|
+
refreshToken = _ref.refreshToken;
|
|
66
73
|
|
|
67
74
|
var isSSR = typeof window === 'undefined';
|
|
68
|
-
var
|
|
75
|
+
var storeHolder = useRef({});
|
|
76
|
+
var baseName = (_b = props.basename) !== null && _b !== void 0 ? _b : router.basePath;
|
|
69
77
|
var onRedirectTo = useCallback(function (_path, opts) {
|
|
70
78
|
var path = _path;
|
|
71
79
|
|
|
@@ -85,7 +93,9 @@ var Connector$1 = function Connector(_props) {
|
|
|
85
93
|
}
|
|
86
94
|
}, []);
|
|
87
95
|
var contextOptions = useMemo(function () {
|
|
88
|
-
return {
|
|
96
|
+
return Object.assign(Object.assign({
|
|
97
|
+
requestCredentials: 'include'
|
|
98
|
+
}, props.contextOptions), {
|
|
89
99
|
baseUrl: function baseUrl(path) {
|
|
90
100
|
if (fronteggAuthApiRoutes.indexOf(path) !== -1 || path.endsWith('/postlogin') || path.endsWith('/prelogin') || path === '/oauth/token') {
|
|
91
101
|
return "".concat(props.envAppUrl, "/api");
|
|
@@ -94,8 +104,41 @@ var Connector$1 = function Connector(_props) {
|
|
|
94
104
|
}
|
|
95
105
|
},
|
|
96
106
|
clientId: props.envClientId
|
|
97
|
-
};
|
|
98
|
-
}, [props.envAppUrl, props.envBaseUrl, props.envClientId]);
|
|
107
|
+
});
|
|
108
|
+
}, [props.envAppUrl, props.envBaseUrl, props.envClientId, props.contextOptions]);
|
|
109
|
+
var authOptions = useMemo(function () {
|
|
110
|
+
var _a, _b, _c, _d;
|
|
111
|
+
|
|
112
|
+
var tenantsState = tenants ? Object.assign({
|
|
113
|
+
tenantTree: null,
|
|
114
|
+
subTenants: [],
|
|
115
|
+
tenants: tenants,
|
|
116
|
+
loading: false
|
|
117
|
+
}, (_a = props.authOptions) === null || _a === void 0 ? void 0 : _a.tenantsState) : undefined;
|
|
118
|
+
var userData = user ? Object.assign(Object.assign(Object.assign({}, user), {
|
|
119
|
+
accessToken: accessToken !== null && accessToken !== void 0 ? accessToken : '',
|
|
120
|
+
refreshToken: refreshToken !== null && refreshToken !== void 0 ? refreshToken : undefined
|
|
121
|
+
}), (_b = props.authOptions) === null || _b === void 0 ? void 0 : _b.user) : null;
|
|
122
|
+
return Object.assign(Object.assign({}, props.authOptions), {
|
|
123
|
+
onRedirectTo: onRedirectTo,
|
|
124
|
+
isLoading: false,
|
|
125
|
+
isAuthenticated: !!session,
|
|
126
|
+
hostedLoginBox: hostedLoginBox !== null && hostedLoginBox !== void 0 ? hostedLoginBox : false,
|
|
127
|
+
disableSilentRefresh: (_d = (_c = props.authOptions) === null || _c === void 0 ? void 0 : _c.disableSilentRefresh) !== null && _d !== void 0 ? _d : false,
|
|
128
|
+
user: userData,
|
|
129
|
+
tenantsState: tenantsState
|
|
130
|
+
});
|
|
131
|
+
}, [accessToken, hostedLoginBox, onRedirectTo, props.authOptions, refreshToken, session, tenants, user]);
|
|
132
|
+
var sharedStore = useMemo(function () {
|
|
133
|
+
var _a;
|
|
134
|
+
|
|
135
|
+
return createFronteggStore({
|
|
136
|
+
context: contextOptions
|
|
137
|
+
}, storeHolder.current, props.previewMode, authOptions, {
|
|
138
|
+
auth: authOptions !== null && authOptions !== void 0 ? authOptions : {},
|
|
139
|
+
audits: (_a = props.auditsOptions) !== null && _a !== void 0 ? _a : {}
|
|
140
|
+
}, false, props.urlStrategy);
|
|
141
|
+
}, [authOptions, contextOptions, props.auditsOptions, props.previewMode, props.urlStrategy]);
|
|
99
142
|
var app = useMemo(function () {
|
|
100
143
|
var _a;
|
|
101
144
|
|
|
@@ -103,34 +146,31 @@ var Connector$1 = function Connector(_props) {
|
|
|
103
146
|
|
|
104
147
|
try {
|
|
105
148
|
createdApp = AppHolder.getInstance(appName !== null && appName !== void 0 ? appName : 'default');
|
|
149
|
+
createdApp.store = sharedStore;
|
|
106
150
|
} catch (e) {
|
|
107
151
|
createdApp = initialize(Object.assign(Object.assign({}, props), {
|
|
152
|
+
store: sharedStore,
|
|
108
153
|
hostedLoginBox: hostedLoginBox !== null && hostedLoginBox !== void 0 ? hostedLoginBox : false,
|
|
109
154
|
customLoginBox: customLoginBox !== null && customLoginBox !== void 0 ? customLoginBox : false,
|
|
110
155
|
basename: (_a = props.basename) !== null && _a !== void 0 ? _a : baseName,
|
|
111
|
-
authOptions:
|
|
112
|
-
|
|
113
|
-
}),
|
|
114
|
-
contextOptions: Object.assign(Object.assign({
|
|
115
|
-
requestCredentials: 'include'
|
|
116
|
-
}, props.contextOptions), contextOptions),
|
|
156
|
+
authOptions: authOptions,
|
|
157
|
+
contextOptions: contextOptions,
|
|
117
158
|
onRedirectTo: onRedirectTo
|
|
118
159
|
}), appName !== null && appName !== void 0 ? appName : 'default');
|
|
119
160
|
}
|
|
120
161
|
|
|
121
162
|
return createdApp;
|
|
122
|
-
}, [appName, props, hostedLoginBox, baseName, onRedirectTo, contextOptions]);
|
|
163
|
+
}, [appName, props, hostedLoginBox, baseName, onRedirectTo, contextOptions, customLoginBox, authOptions, sharedStore]);
|
|
123
164
|
ContextHolder.setOnRedirectTo(onRedirectTo);
|
|
124
165
|
useEffect(function () {
|
|
125
|
-
|
|
126
|
-
// @ts-ignore
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
app.store.dispatch({
|
|
166
|
+
app === null || app === void 0 ? void 0 : app.store.dispatch({
|
|
130
167
|
type: 'auth/requestAuthorizeSSR',
|
|
131
|
-
payload:
|
|
132
|
-
|
|
133
|
-
|
|
168
|
+
payload: {
|
|
169
|
+
accessToken: accessToken,
|
|
170
|
+
user: user ? Object.assign(Object.assign({}, user), {
|
|
171
|
+
refreshToken: refreshToken
|
|
172
|
+
}) : null,
|
|
173
|
+
tenants: tenants
|
|
134
174
|
}
|
|
135
175
|
});
|
|
136
176
|
}, [app]);
|
|
@@ -1214,6 +1254,15 @@ var FronteggConfig = /*#__PURE__*/function () {
|
|
|
1214
1254
|
|
|
1215
1255
|
return (_a = this.getEnvAppUrl()) !== null && _a !== void 0 ? _a : 'http://localhost:3000';
|
|
1216
1256
|
}
|
|
1257
|
+
}, {
|
|
1258
|
+
key: "appEnvConfig",
|
|
1259
|
+
get: function get() {
|
|
1260
|
+
return {
|
|
1261
|
+
envAppUrl: this.getEnvAppUrl(),
|
|
1262
|
+
envBaseUrl: process.env['FRONTEGG_BASE_URL'],
|
|
1263
|
+
envClientId: process.env['FRONTEGG_CLIENT_ID']
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1217
1266
|
}, {
|
|
1218
1267
|
key: "cookieDomain",
|
|
1219
1268
|
get: function get() {
|
|
@@ -1627,6 +1676,115 @@ function withSSRSession(handler) {
|
|
|
1627
1676
|
};
|
|
1628
1677
|
}
|
|
1629
1678
|
|
|
1679
|
+
var BASE_URL = "".concat(process.env['FRONTEGG_BASE_URL'], "/frontegg");
|
|
1680
|
+
|
|
1681
|
+
var Get = function Get(_ref) {
|
|
1682
|
+
var url = _ref.url,
|
|
1683
|
+
_ref$credentials = _ref.credentials,
|
|
1684
|
+
credentials = _ref$credentials === void 0 ? 'include' : _ref$credentials,
|
|
1685
|
+
headers = _ref.headers;
|
|
1686
|
+
return fetch(url, {
|
|
1687
|
+
method: 'GET',
|
|
1688
|
+
credentials: credentials,
|
|
1689
|
+
headers: headers
|
|
1690
|
+
});
|
|
1691
|
+
};
|
|
1692
|
+
|
|
1693
|
+
var extractHeaders = function extractHeaders(headers) {
|
|
1694
|
+
return {
|
|
1695
|
+
'accept-encoding': headers['accept-encoding'],
|
|
1696
|
+
'accept-language': headers['accept-language'],
|
|
1697
|
+
cookie: headers['cookie'],
|
|
1698
|
+
accept: headers['accept'],
|
|
1699
|
+
'user-agent': headers['user-agent'],
|
|
1700
|
+
connection: headers['connection'],
|
|
1701
|
+
'cache-control': headers['cache-control'],
|
|
1702
|
+
'Authorization': headers['Authorization']
|
|
1703
|
+
};
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
var parseResponse = function parseResponse(res) {
|
|
1707
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
1708
|
+
var resText;
|
|
1709
|
+
return regenerator.wrap(function _callee$(_context) {
|
|
1710
|
+
while (1) {
|
|
1711
|
+
switch (_context.prev = _context.next) {
|
|
1712
|
+
case 0:
|
|
1713
|
+
if (res.ok) {
|
|
1714
|
+
_context.next = 2;
|
|
1715
|
+
break;
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
return _context.abrupt("return", undefined);
|
|
1719
|
+
|
|
1720
|
+
case 2:
|
|
1721
|
+
_context.next = 4;
|
|
1722
|
+
return res.text();
|
|
1723
|
+
|
|
1724
|
+
case 4:
|
|
1725
|
+
resText = _context.sent;
|
|
1726
|
+
return _context.abrupt("return", JSON.parse(resText));
|
|
1727
|
+
|
|
1728
|
+
case 6:
|
|
1729
|
+
case "end":
|
|
1730
|
+
return _context.stop();
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
}, _callee);
|
|
1734
|
+
}));
|
|
1735
|
+
};
|
|
1736
|
+
|
|
1737
|
+
var getUsers = function getUsers(headers) {
|
|
1738
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
|
|
1739
|
+
var res;
|
|
1740
|
+
return regenerator.wrap(function _callee2$(_context2) {
|
|
1741
|
+
while (1) {
|
|
1742
|
+
switch (_context2.prev = _context2.next) {
|
|
1743
|
+
case 0:
|
|
1744
|
+
_context2.next = 2;
|
|
1745
|
+
return Get({
|
|
1746
|
+
url: "".concat(BASE_URL).concat(fronteggUsersUrl),
|
|
1747
|
+
headers: extractHeaders(headers)
|
|
1748
|
+
});
|
|
1749
|
+
|
|
1750
|
+
case 2:
|
|
1751
|
+
res = _context2.sent;
|
|
1752
|
+
return _context2.abrupt("return", parseResponse(res));
|
|
1753
|
+
|
|
1754
|
+
case 4:
|
|
1755
|
+
case "end":
|
|
1756
|
+
return _context2.stop();
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
}, _callee2);
|
|
1760
|
+
}));
|
|
1761
|
+
};
|
|
1762
|
+
var getTenants = function getTenants(headers) {
|
|
1763
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
|
|
1764
|
+
var res;
|
|
1765
|
+
return regenerator.wrap(function _callee3$(_context3) {
|
|
1766
|
+
while (1) {
|
|
1767
|
+
switch (_context3.prev = _context3.next) {
|
|
1768
|
+
case 0:
|
|
1769
|
+
_context3.next = 2;
|
|
1770
|
+
return Get({
|
|
1771
|
+
url: "".concat(BASE_URL).concat(fronteggTenantsUrl),
|
|
1772
|
+
headers: extractHeaders(headers)
|
|
1773
|
+
});
|
|
1774
|
+
|
|
1775
|
+
case 2:
|
|
1776
|
+
res = _context3.sent;
|
|
1777
|
+
return _context3.abrupt("return", parseResponse(res));
|
|
1778
|
+
|
|
1779
|
+
case 4:
|
|
1780
|
+
case "end":
|
|
1781
|
+
return _context3.stop();
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
}, _callee3);
|
|
1785
|
+
}));
|
|
1786
|
+
};
|
|
1787
|
+
|
|
1630
1788
|
function rewriteCookieProperty(header, config, property) {
|
|
1631
1789
|
if (Array.isArray(header)) {
|
|
1632
1790
|
return header.map(function (headerElement) {
|
|
@@ -2103,6 +2261,58 @@ var modifySetCookieIfUnsecure = function modifySetCookieIfUnsecure(setCookieValu
|
|
|
2103
2261
|
|
|
2104
2262
|
return setCookieValue;
|
|
2105
2263
|
};
|
|
2264
|
+
function meAndTenants(ctx, accessToken) {
|
|
2265
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee5() {
|
|
2266
|
+
var request, headers, _yield$Promise$all, _yield$Promise$all2, user, tenants;
|
|
2267
|
+
|
|
2268
|
+
return regenerator.wrap(function _callee5$(_context5) {
|
|
2269
|
+
while (1) {
|
|
2270
|
+
switch (_context5.prev = _context5.next) {
|
|
2271
|
+
case 0:
|
|
2272
|
+
request = ctx.req;
|
|
2273
|
+
|
|
2274
|
+
if (!(!request || !accessToken)) {
|
|
2275
|
+
_context5.next = 3;
|
|
2276
|
+
break;
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
return _context5.abrupt("return", {});
|
|
2280
|
+
|
|
2281
|
+
case 3:
|
|
2282
|
+
headers = Object.assign(Object.assign({}, request.headers), {
|
|
2283
|
+
Authorization: "Bearer ".concat(accessToken)
|
|
2284
|
+
});
|
|
2285
|
+
_context5.next = 6;
|
|
2286
|
+
return Promise.all([getUsers(headers), getTenants(headers)]);
|
|
2287
|
+
|
|
2288
|
+
case 6:
|
|
2289
|
+
_yield$Promise$all = _context5.sent;
|
|
2290
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
2291
|
+
user = _yield$Promise$all2[0];
|
|
2292
|
+
tenants = _yield$Promise$all2[1];
|
|
2293
|
+
return _context5.abrupt("return", {
|
|
2294
|
+
user: user,
|
|
2295
|
+
tenants: tenants
|
|
2296
|
+
});
|
|
2297
|
+
|
|
2298
|
+
case 11:
|
|
2299
|
+
case "end":
|
|
2300
|
+
return _context5.stop();
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
}, _callee5);
|
|
2304
|
+
}));
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
var envError = function envError(varName) {
|
|
2308
|
+
return "@frontegg/nextjs: .env.local must contain ".concat(varName);
|
|
2309
|
+
};
|
|
2310
|
+
|
|
2311
|
+
var fronteggErrors = {
|
|
2312
|
+
envAppUrl: envError('FRONTEGG_APP_URL'),
|
|
2313
|
+
envBaseUrl: envError('FRONTEGG_BASE_URL'),
|
|
2314
|
+
envClientId: envError('FRONTEGG_CLIENT_ID')
|
|
2315
|
+
};
|
|
2106
2316
|
|
|
2107
2317
|
var withFronteggApp = function withFronteggApp(app, options) {
|
|
2108
2318
|
var _a, _b;
|
|
@@ -2111,7 +2321,7 @@ var withFronteggApp = function withFronteggApp(app, options) {
|
|
|
2111
2321
|
|
|
2112
2322
|
app.getInitialProps = function (appContext) {
|
|
2113
2323
|
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
2114
|
-
var
|
|
2324
|
+
var ctx, Component, session, _yield$meAndTenants, user, tenants, _fronteggConfig$appEn, envAppUrl, envBaseUrl, envClientId;
|
|
2115
2325
|
|
|
2116
2326
|
return regenerator.wrap(function _callee$(_context) {
|
|
2117
2327
|
while (1) {
|
|
@@ -2119,8 +2329,8 @@ var withFronteggApp = function withFronteggApp(app, options) {
|
|
|
2119
2329
|
case 0:
|
|
2120
2330
|
ctx = appContext.ctx, Component = appContext.Component;
|
|
2121
2331
|
|
|
2122
|
-
if (!
|
|
2123
|
-
_context.next =
|
|
2332
|
+
if (!ctx.req) {
|
|
2333
|
+
_context.next = 47;
|
|
2124
2334
|
break;
|
|
2125
2335
|
}
|
|
2126
2336
|
|
|
@@ -2129,79 +2339,90 @@ var withFronteggApp = function withFronteggApp(app, options) {
|
|
|
2129
2339
|
|
|
2130
2340
|
case 4:
|
|
2131
2341
|
session = _context.sent;
|
|
2342
|
+
_context.next = 7;
|
|
2343
|
+
return meAndTenants(ctx, session === null || session === void 0 ? void 0 : session.accessToken);
|
|
2344
|
+
|
|
2345
|
+
case 7:
|
|
2346
|
+
_yield$meAndTenants = _context.sent;
|
|
2347
|
+
user = _yield$meAndTenants.user;
|
|
2348
|
+
tenants = _yield$meAndTenants.tenants;
|
|
2132
2349
|
appContext.session = session;
|
|
2133
|
-
|
|
2350
|
+
appContext.user = user;
|
|
2351
|
+
appContext.tenants = tenants;
|
|
2352
|
+
_fronteggConfig$appEn = fronteggConfig.appEnvConfig, envAppUrl = _fronteggConfig$appEn.envAppUrl, envBaseUrl = _fronteggConfig$appEn.envBaseUrl, envClientId = _fronteggConfig$appEn.envClientId;
|
|
2134
2353
|
|
|
2135
2354
|
if (envAppUrl) {
|
|
2136
|
-
_context.next =
|
|
2355
|
+
_context.next = 16;
|
|
2137
2356
|
break;
|
|
2138
2357
|
}
|
|
2139
2358
|
|
|
2140
|
-
throw Error(
|
|
2359
|
+
throw Error(fronteggErrors.envAppUrl);
|
|
2141
2360
|
|
|
2142
|
-
case
|
|
2143
|
-
if (
|
|
2144
|
-
_context.next =
|
|
2361
|
+
case 16:
|
|
2362
|
+
if (envBaseUrl) {
|
|
2363
|
+
_context.next = 18;
|
|
2145
2364
|
break;
|
|
2146
2365
|
}
|
|
2147
2366
|
|
|
2148
|
-
throw Error(
|
|
2367
|
+
throw Error(fronteggErrors.envBaseUrl);
|
|
2149
2368
|
|
|
2150
|
-
case
|
|
2151
|
-
if (
|
|
2152
|
-
_context.next =
|
|
2369
|
+
case 18:
|
|
2370
|
+
if (envClientId) {
|
|
2371
|
+
_context.next = 20;
|
|
2153
2372
|
break;
|
|
2154
2373
|
}
|
|
2155
2374
|
|
|
2156
|
-
throw Error(
|
|
2375
|
+
throw Error(fronteggErrors.envClientId);
|
|
2157
2376
|
|
|
2158
|
-
case
|
|
2377
|
+
case 20:
|
|
2159
2378
|
_context.t0 = Object;
|
|
2160
2379
|
_context.t1 = Object;
|
|
2161
2380
|
_context.t2 = Object;
|
|
2162
2381
|
_context.t3 = {};
|
|
2163
2382
|
|
|
2164
2383
|
if (!originalGetInitialProps) {
|
|
2165
|
-
_context.next =
|
|
2384
|
+
_context.next = 30;
|
|
2166
2385
|
break;
|
|
2167
2386
|
}
|
|
2168
2387
|
|
|
2169
|
-
_context.next =
|
|
2388
|
+
_context.next = 27;
|
|
2170
2389
|
return originalGetInitialProps(appContext);
|
|
2171
2390
|
|
|
2172
|
-
case
|
|
2391
|
+
case 27:
|
|
2173
2392
|
_context.t4 = _context.sent;
|
|
2174
|
-
_context.next =
|
|
2393
|
+
_context.next = 31;
|
|
2175
2394
|
break;
|
|
2176
2395
|
|
|
2177
|
-
case
|
|
2396
|
+
case 30:
|
|
2178
2397
|
_context.t4 = {};
|
|
2179
2398
|
|
|
2180
|
-
case
|
|
2399
|
+
case 31:
|
|
2181
2400
|
_context.t5 = _context.t4;
|
|
2182
2401
|
_context.t6 = _context.t2.assign.call(_context.t2, _context.t3, _context.t5);
|
|
2183
2402
|
|
|
2184
2403
|
if (!Component.getInitialProps) {
|
|
2185
|
-
_context.next =
|
|
2404
|
+
_context.next = 39;
|
|
2186
2405
|
break;
|
|
2187
2406
|
}
|
|
2188
2407
|
|
|
2189
|
-
_context.next =
|
|
2408
|
+
_context.next = 36;
|
|
2190
2409
|
return Component.getInitialProps(ctx);
|
|
2191
2410
|
|
|
2192
|
-
case
|
|
2411
|
+
case 36:
|
|
2193
2412
|
_context.t7 = _context.sent;
|
|
2194
|
-
_context.next =
|
|
2413
|
+
_context.next = 40;
|
|
2195
2414
|
break;
|
|
2196
2415
|
|
|
2197
|
-
case
|
|
2416
|
+
case 39:
|
|
2198
2417
|
_context.t7 = {};
|
|
2199
2418
|
|
|
2200
|
-
case
|
|
2419
|
+
case 40:
|
|
2201
2420
|
_context.t8 = _context.t7;
|
|
2202
2421
|
_context.t9 = _context.t1.assign.call(_context.t1, _context.t6, _context.t8);
|
|
2203
2422
|
_context.t10 = {
|
|
2204
2423
|
session: session,
|
|
2424
|
+
user: user,
|
|
2425
|
+
tenants: tenants,
|
|
2205
2426
|
envAppUrl: envAppUrl,
|
|
2206
2427
|
envBaseUrl: process.env['FRONTEGG_BASE_URL'],
|
|
2207
2428
|
envClientId: process.env['FRONTEGG_CLIENT_ID']
|
|
@@ -2211,56 +2432,56 @@ var withFronteggApp = function withFronteggApp(app, options) {
|
|
|
2211
2432
|
pageProps: _context.t11
|
|
2212
2433
|
});
|
|
2213
2434
|
|
|
2214
|
-
case
|
|
2435
|
+
case 47:
|
|
2215
2436
|
appContext.session = null;
|
|
2216
2437
|
_context.t12 = Object;
|
|
2217
2438
|
_context.t13 = Object;
|
|
2218
2439
|
_context.t14 = {};
|
|
2219
2440
|
|
|
2220
2441
|
if (!originalGetInitialProps) {
|
|
2221
|
-
_context.next =
|
|
2442
|
+
_context.next = 57;
|
|
2222
2443
|
break;
|
|
2223
2444
|
}
|
|
2224
2445
|
|
|
2225
|
-
_context.next =
|
|
2446
|
+
_context.next = 54;
|
|
2226
2447
|
return originalGetInitialProps(appContext);
|
|
2227
2448
|
|
|
2228
|
-
case
|
|
2449
|
+
case 54:
|
|
2229
2450
|
_context.t15 = _context.sent;
|
|
2230
|
-
_context.next =
|
|
2451
|
+
_context.next = 58;
|
|
2231
2452
|
break;
|
|
2232
2453
|
|
|
2233
|
-
case
|
|
2454
|
+
case 57:
|
|
2234
2455
|
_context.t15 = {};
|
|
2235
2456
|
|
|
2236
|
-
case
|
|
2457
|
+
case 58:
|
|
2237
2458
|
_context.t16 = _context.t15;
|
|
2238
2459
|
_context.t17 = _context.t13.assign.call(_context.t13, _context.t14, _context.t16);
|
|
2239
2460
|
|
|
2240
2461
|
if (!Component.getInitialProps) {
|
|
2241
|
-
_context.next =
|
|
2462
|
+
_context.next = 66;
|
|
2242
2463
|
break;
|
|
2243
2464
|
}
|
|
2244
2465
|
|
|
2245
|
-
_context.next =
|
|
2466
|
+
_context.next = 63;
|
|
2246
2467
|
return Component.getInitialProps(ctx);
|
|
2247
2468
|
|
|
2248
|
-
case
|
|
2469
|
+
case 63:
|
|
2249
2470
|
_context.t18 = _context.sent;
|
|
2250
|
-
_context.next =
|
|
2471
|
+
_context.next = 67;
|
|
2251
2472
|
break;
|
|
2252
2473
|
|
|
2253
|
-
case
|
|
2474
|
+
case 66:
|
|
2254
2475
|
_context.t18 = {};
|
|
2255
2476
|
|
|
2256
|
-
case
|
|
2477
|
+
case 67:
|
|
2257
2478
|
_context.t19 = _context.t18;
|
|
2258
2479
|
_context.t20 = _context.t12.assign.call(_context.t12, _context.t17, _context.t19);
|
|
2259
2480
|
return _context.abrupt("return", {
|
|
2260
2481
|
pageProps: _context.t20
|
|
2261
2482
|
});
|
|
2262
2483
|
|
|
2263
|
-
case
|
|
2484
|
+
case 70:
|
|
2264
2485
|
case "end":
|
|
2265
2486
|
return _context.stop();
|
|
2266
2487
|
}
|
|
@@ -2273,11 +2494,20 @@ var withFronteggApp = function withFronteggApp(app, options) {
|
|
|
2273
2494
|
fronteggConfig.fronteggAppOptions = options !== null && options !== void 0 ? options : {};
|
|
2274
2495
|
|
|
2275
2496
|
function CustomFronteggApp(appProps) {
|
|
2497
|
+
var _appProps$pageProps = appProps.pageProps,
|
|
2498
|
+
user = _appProps$pageProps.user,
|
|
2499
|
+
tenants = _appProps$pageProps.tenants,
|
|
2500
|
+
session = _appProps$pageProps.session,
|
|
2501
|
+
envAppUrl = _appProps$pageProps.envAppUrl,
|
|
2502
|
+
envBaseUrl = _appProps$pageProps.envBaseUrl,
|
|
2503
|
+
envClientId = _appProps$pageProps.envClientId;
|
|
2276
2504
|
return jsx(FronteggProvider, Object.assign({}, options, {
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2505
|
+
user: user,
|
|
2506
|
+
tenants: tenants,
|
|
2507
|
+
session: session,
|
|
2508
|
+
envAppUrl: envAppUrl,
|
|
2509
|
+
envBaseUrl: envBaseUrl,
|
|
2510
|
+
envClientId: envClientId
|
|
2281
2511
|
}, {
|
|
2282
2512
|
children: app(appProps)
|
|
2283
2513
|
}));
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/nextjs",
|
|
3
|
-
"version": "6.7.6-alpha.
|
|
3
|
+
"version": "6.7.6-alpha.3676548486",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@frontegg/js": "6.
|
|
6
|
-
"@frontegg/react-hooks": "6.
|
|
5
|
+
"@frontegg/js": "6.50.0",
|
|
6
|
+
"@frontegg/react-hooks": "6.50.0",
|
|
7
7
|
"jose": "^4.9.2",
|
|
8
8
|
"iron-session": "^6.2.1",
|
|
9
9
|
"http-proxy": "^1.18.1",
|
package/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ILoginResponse, ITenantsResponse } from '@frontegg/rest-api';
|
|
1
2
|
export interface AccountEnvironment {
|
|
2
3
|
id: string;
|
|
3
4
|
createdAt: string;
|
|
@@ -28,6 +29,15 @@ export interface FronteggNextJSSession {
|
|
|
28
29
|
iss: string;
|
|
29
30
|
};
|
|
30
31
|
}
|
|
32
|
+
export interface AppEnvConfig {
|
|
33
|
+
envAppUrl?: string;
|
|
34
|
+
envBaseUrl?: string;
|
|
35
|
+
envClientId?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface MeAndTenants {
|
|
38
|
+
user?: ILoginResponse;
|
|
39
|
+
tenants?: ITenantsResponse[];
|
|
40
|
+
}
|
|
31
41
|
declare module 'iron-session' {
|
|
32
42
|
interface IronSessionData {
|
|
33
43
|
accessToken: FronteggNextJSSession['accessToken'];
|