@frontegg/nextjs 6.7.20 → 6.7.21-alpha.4441971157
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +19 -37
- package/api/index.d.ts +19 -0
- package/api/index.js +87 -0
- package/api/index.js.map +1 -0
- package/api/package.json +6 -0
- package/api/urls.d.ts +33 -0
- package/api/urls.js +56 -0
- package/api/urls.js.map +1 -0
- package/api/utils.d.ts +46 -0
- package/api/utils.js +123 -0
- package/api/utils.js.map +1 -0
- package/app/ClientFronteggProvider.d.ts +3 -0
- package/app/ClientFronteggProvider.js +32 -0
- package/app/ClientFronteggProvider.js.map +1 -0
- package/app/FronteggAppProvider.d.ts +4 -0
- package/app/FronteggAppProvider.js +25 -0
- package/app/FronteggAppProvider.js.map +1 -0
- package/{client → app}/FronteggAppRouter.d.ts +11 -10
- package/app/FronteggAppRouter.js +38 -0
- package/app/FronteggAppRouter.js.map +1 -0
- package/app/helpers.d.ts +5 -0
- package/app/helpers.js +43 -0
- package/app/helpers.js.map +1 -0
- package/app/index.d.ts +4 -0
- package/app/index.js +39 -0
- package/app/index.js.map +1 -0
- package/app/package.json +6 -0
- package/common/{client/AppContext.d.ts → AppContext.d.ts} +4 -4
- package/common/AppContext.js +12 -0
- package/common/AppContext.js.map +1 -0
- package/{AuthorizedContent.d.ts → common/AuthorizedContent.d.ts} +9 -8
- package/common/AuthorizedContent.js +54 -0
- package/common/AuthorizedContent.js.map +1 -0
- package/common/{client/FronteggBaseProvider.d.ts → FronteggBaseProvider.d.ts} +3 -3
- package/common/FronteggBaseProvider.js +76 -0
- package/common/FronteggBaseProvider.js.map +1 -0
- package/common/FronteggRouterBase.d.ts +9 -0
- package/common/FronteggRouterBase.js +48 -0
- package/common/FronteggRouterBase.js.map +1 -0
- package/common/helpers.d.ts +3 -9
- package/common/helpers.js +32 -0
- package/common/helpers.js.map +1 -0
- package/common/index.d.ts +4 -6
- package/common/index.js +45 -10
- package/common/index.js.map +1 -1
- package/common/package.json +6 -0
- package/common/useRequestAuthorizeSSR.d.ts +5 -0
- package/common/useRequestAuthorizeSSR.js +30 -0
- package/common/useRequestAuthorizeSSR.js.map +1 -0
- package/config/constants.d.ts +57 -0
- package/config/constants.js +20 -0
- package/config/constants.js.map +1 -0
- package/config/helpers.d.ts +28 -0
- package/config/helpers.js +97 -0
- package/config/helpers.js.map +1 -0
- package/config/index.d.ts +24 -0
- package/config/index.js +94 -0
- package/config/index.js.map +1 -0
- package/config/package.json +6 -0
- package/config/types.d.ts +18 -0
- package/config/types.js +6 -0
- package/config/types.js.map +1 -0
- package/edge/getSessionOnEdge.d.ts +3 -2
- package/edge/getSessionOnEdge.js +16 -0
- package/edge/getSessionOnEdge.js.map +1 -0
- package/edge/index.d.ts +3 -2
- package/edge/index.js +38 -63
- package/edge/index.js.map +1 -1
- package/edge/package.json +6 -0
- package/edge/redirectToLogin.d.ts +2 -0
- package/edge/redirectToLogin.js +16 -0
- package/edge/redirectToLogin.js.map +1 -0
- package/edge/shouldBypassMiddleware.d.ts +21 -7
- package/edge/shouldBypassMiddleware.js +50 -0
- package/edge/shouldBypassMiddleware.js.map +1 -0
- package/index.d.ts +7 -11
- package/index.js +98 -1392
- package/index.js.map +1 -1
- package/middleware/FronteggApiMiddleware.d.ts +8 -0
- package/middleware/FronteggApiMiddleware.js +34 -0
- package/middleware/FronteggApiMiddleware.js.map +1 -0
- package/middleware/FronteggProxy.d.ts +4 -0
- package/middleware/FronteggProxy.js +31 -0
- package/middleware/FronteggProxy.js.map +1 -0
- package/middleware/ProxyRequestCallback.d.ts +13 -0
- package/middleware/ProxyRequestCallback.js +56 -0
- package/middleware/ProxyRequestCallback.js.map +1 -0
- package/middleware/ProxyResponseCallback.d.ts +13 -0
- package/middleware/ProxyResponseCallback.js +111 -0
- package/middleware/ProxyResponseCallback.js.map +1 -0
- package/middleware/constants.d.ts +8 -0
- package/middleware/constants.js +17 -0
- package/middleware/constants.js.map +1 -0
- package/{common/FronteggProxy.d.ts → middleware/helpers.d.ts} +13 -26
- package/middleware/helpers.js +42 -0
- package/middleware/helpers.js.map +1 -0
- package/middleware/index.d.ts +23 -0
- package/middleware/index.js +13 -0
- package/middleware/index.js.map +1 -0
- package/middleware/package.json +6 -0
- package/no-ssr/ExpireInListener.d.ts +2 -0
- package/no-ssr/ExpireInListener.js +29 -0
- package/no-ssr/ExpireInListener.js.map +1 -0
- package/{FronteggProviderNoSSR.d.ts → no-ssr/FronteggProviderNoSSR.d.ts} +4 -4
- package/no-ssr/FronteggProviderNoSSR.js +84 -0
- package/no-ssr/FronteggProviderNoSSR.js.map +1 -0
- package/no-ssr/index.d.ts +2 -0
- package/no-ssr/index.js +13 -0
- package/no-ssr/index.js.map +1 -0
- package/no-ssr/package.json +6 -0
- package/package.json +6 -7
- package/pages/FronteggPagesProvider/index.d.ts +4 -0
- package/pages/FronteggPagesProvider/index.js +32 -0
- package/pages/FronteggPagesProvider/index.js.map +1 -0
- package/pages/FronteggPagesProvider/package.json +6 -0
- package/{FronteggRouter.d.ts → pages/FronteggRouter/FronteggRouter.d.ts} +6 -5
- package/pages/FronteggRouter/FronteggRouter.js +46 -0
- package/pages/FronteggRouter/FronteggRouter.js.map +1 -0
- package/pages/FronteggRouter/index.d.ts +26 -0
- package/pages/FronteggRouter/index.js +19 -0
- package/pages/FronteggRouter/index.js.map +1 -0
- package/pages/FronteggRouter/package.json +6 -0
- package/{session.d.ts → pages/helpers.d.ts} +10 -10
- package/pages/helpers.js +40 -0
- package/pages/helpers.js.map +1 -0
- package/pages/index.d.ts +3 -0
- package/pages/index.js +47 -0
- package/pages/index.js.map +1 -0
- package/pages/package.json +6 -0
- package/pages/withFronteggApp/index.d.ts +2 -0
- package/pages/withFronteggApp/index.js +13 -0
- package/pages/withFronteggApp/index.js.map +1 -0
- package/pages/withFronteggApp/package.json +6 -0
- package/pages/withFronteggApp/types.d.ts +12 -0
- package/pages/withFronteggApp/types.js +6 -0
- package/pages/withFronteggApp/types.js.map +1 -0
- package/pages/withFronteggApp/withFronteggApp.d.ts +2 -0
- package/pages/withFronteggApp/withFronteggApp.js +70 -0
- package/pages/withFronteggApp/withFronteggApp.js.map +1 -0
- package/sdkVersion.d.ts +4 -4
- package/sdkVersion.js +11 -0
- package/sdkVersion.js.map +1 -0
- package/{common/types.d.ts → types/index.d.ts} +80 -74
- package/types/index.js +6 -0
- package/types/index.js.map +1 -0
- package/types/package.json +6 -0
- package/utils/common/constants.d.ts +12 -0
- package/utils/common/constants.js +23 -0
- package/utils/common/constants.js.map +1 -0
- package/utils/common/index.d.ts +15 -0
- package/utils/common/index.js +32 -0
- package/utils/common/index.js.map +1 -0
- package/utils/common/package.json +6 -0
- package/utils/cookies/constants.d.ts +7 -0
- package/utils/cookies/constants.js +15 -0
- package/utils/cookies/constants.js.map +1 -0
- package/utils/cookies/helpers.d.ts +25 -0
- package/utils/cookies/helpers.js +64 -0
- package/utils/cookies/helpers.js.map +1 -0
- package/utils/cookies/index.d.ts +45 -0
- package/utils/cookies/index.js +239 -0
- package/utils/cookies/index.js.map +1 -0
- package/utils/cookies/package.json +6 -0
- package/utils/cookies/serializer.d.ts +22 -0
- package/utils/cookies/serializer.js +161 -0
- package/utils/cookies/serializer.js.map +1 -0
- package/utils/cookies/types.d.ts +31 -0
- package/utils/cookies/types.js +6 -0
- package/utils/cookies/types.js.map +1 -0
- package/utils/createSession/index.d.ts +2 -0
- package/utils/createSession/index.js +51 -0
- package/utils/createSession/index.js.map +1 -0
- package/utils/createSession/package.json +6 -0
- package/utils/encryption/index.d.ts +3 -0
- package/utils/encryption/index.js +37 -0
- package/utils/encryption/index.js.map +1 -0
- package/utils/encryption/package.json +6 -0
- package/utils/encryption-edge/index.d.ts +3 -0
- package/utils/encryption-edge/index.js +37 -0
- package/utils/encryption-edge/index.js.map +1 -0
- package/utils/encryption-edge/package.json +6 -0
- package/utils/errors/FronteggEnvNotFound.d.ts +3 -0
- package/utils/errors/FronteggEnvNotFound.js +15 -0
- package/utils/errors/FronteggEnvNotFound.js.map +1 -0
- package/utils/errors/InvalidFronteggEnv.d.ts +3 -0
- package/utils/errors/InvalidFronteggEnv.js +15 -0
- package/utils/errors/InvalidFronteggEnv.js.map +1 -0
- package/utils/errors/index.d.ts +2 -0
- package/utils/errors/index.js +28 -0
- package/utils/errors/index.js.map +1 -0
- package/utils/errors/package.json +6 -0
- package/utils/fetchUserData/index.d.ts +7 -0
- package/utils/fetchUserData/index.js +56 -0
- package/utils/fetchUserData/index.js.map +1 -0
- package/utils/fetchUserData/package.json +6 -0
- package/utils/fronteggLogger/constants.d.ts +13 -0
- package/utils/fronteggLogger/constants.js +28 -0
- package/utils/fronteggLogger/constants.js.map +1 -0
- package/utils/fronteggLogger/index.d.ts +17 -0
- package/utils/fronteggLogger/index.js +67 -0
- package/utils/fronteggLogger/index.js.map +1 -0
- package/utils/fronteggLogger/package.json +6 -0
- package/{common/client/createOrGetFronteggApp.d.ts → utils/initializeFronteggApp/index.d.ts} +11 -11
- package/utils/initializeFronteggApp/index.js +108 -0
- package/utils/initializeFronteggApp/index.js.map +1 -0
- package/utils/initializeFronteggApp/package.json +6 -0
- package/utils/jwt/index.d.ts +22 -0
- package/utils/jwt/index.js +61 -0
- package/utils/jwt/index.js.map +1 -0
- package/utils/jwt/package.json +6 -0
- package/utils/refreshAccessToken/helpers.d.ts +16 -0
- package/utils/refreshAccessToken/helpers.js +80 -0
- package/utils/refreshAccessToken/helpers.js.map +1 -0
- package/utils/refreshAccessToken/index.d.ts +9 -0
- package/utils/refreshAccessToken/index.js +94 -0
- package/utils/refreshAccessToken/index.js.map +1 -0
- package/utils/refreshAccessToken/package.json +6 -0
- package/utils/routing/index.d.ts +5 -0
- package/utils/routing/index.js +31 -0
- package/utils/routing/index.js.map +1 -0
- package/utils/routing/package.json +6 -0
- package/utils/useOnRedirectTo/index.d.ts +5 -0
- package/utils/useOnRedirectTo/index.js +28 -0
- package/utils/useOnRedirectTo/index.js.map +1 -0
- package/utils/useOnRedirectTo/package.json +6 -0
- package/CookieManager-e50dc144.js +0 -322
- package/CookieManager-e50dc144.js.map +0 -1
- package/FronteggClientProviderNext13-b3c1e7a0.js +0 -158
- package/FronteggClientProviderNext13-b3c1e7a0.js.map +0 -1
- package/FronteggMiddleware.d.ts +0 -15
- package/FronteggProvider.d.ts +0 -3
- package/api-25516652.js +0 -58
- package/api-25516652.js.map +0 -1
- package/client/FronteggClientProviderNext13.d.ts +0 -3
- package/client/index.d.ts +0 -2
- package/client/index.js +0 -64
- package/client/index.js.map +0 -1
- package/common/CookieManager.d.ts +0 -41
- package/common/FronteggConfig.d.ts +0 -31
- package/common/api.d.ts +0 -3
- package/common/client/ExpireInListener.d.ts +0 -2
- package/common/client/hooks/index.d.ts +0 -1
- package/common/client/hooks/useRequestAuthorizeSSR.d.ts +0 -5
- package/common/client/index.d.ts +0 -4
- package/common/consts.d.ts +0 -6
- package/common/createGetSession.d.ts +0 -7
- package/common/utils.d.ts +0 -1
- package/createGetSession-2e1e4506.js +0 -50
- package/createGetSession-2e1e4506.js.map +0 -1
- package/helpers-dac37998.js +0 -88
- package/helpers-dac37998.js.map +0 -1
- package/refreshToken.d.ts +0 -3
- package/server/FronteggProviderNext13.d.ts +0 -3
- package/server/getSessionNext13.d.ts +0 -4
- package/server/index.d.ts +0 -2
- package/server/index.js +0 -84
- package/server/index.js.map +0 -1
- package/withFronteggApp.d.ts +0 -11
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = useRequestAuthorizeSSR;
|
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
function useRequestAuthorizeSSR({
|
|
12
|
+
app,
|
|
13
|
+
user,
|
|
14
|
+
tenants,
|
|
15
|
+
session
|
|
16
|
+
}) {
|
|
17
|
+
(0, _react.useEffect)(() => {
|
|
18
|
+
app == null ? void 0 : app.store.dispatch({
|
|
19
|
+
type: 'auth/requestAuthorizeSSR',
|
|
20
|
+
payload: {
|
|
21
|
+
accessToken: session == null ? void 0 : session.accessToken,
|
|
22
|
+
user: user ? (0, _extends2.default)({}, user, {
|
|
23
|
+
refreshToken: session == null ? void 0 : session.refreshToken
|
|
24
|
+
}) : null,
|
|
25
|
+
tenants
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}, [app]);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=useRequestAuthorizeSSR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequestAuthorizeSSR.js","names":["useRequestAuthorizeSSR","app","user","tenants","session","useEffect","store","dispatch","type","payload","accessToken","refreshToken"],"sources":["../../../../packages/nextjs/src/common/useRequestAuthorizeSSR.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { FronteggApp } from '@frontegg/js';\nimport { AllUserData } from '../types';\n\nexport default function useRequestAuthorizeSSR({ app, user, tenants, session }: { app: FronteggApp } & AllUserData) {\n useEffect(() => {\n app?.store.dispatch({\n type: 'auth/requestAuthorizeSSR',\n payload: {\n accessToken: session?.accessToken,\n user: user ? { ...user, refreshToken: session?.refreshToken } : null,\n tenants,\n },\n });\n }, [app]);\n}\n"],"mappings":";AAAA,YAAY;;AAAC;AAAA;EAAA;AAAA;AAAA;AAAA;AAEb;AAIe,SAASA,sBAAsB,CAAC;EAAEC,GAAG;EAAEC,IAAI;EAAEC,OAAO;EAAEC;AAA4C,CAAC,EAAE;EAClH,IAAAC,gBAAS,EAAC,MAAM;IACdJ,GAAG,oBAAHA,GAAG,CAAEK,KAAK,CAACC,QAAQ,CAAC;MAClBC,IAAI,EAAE,0BAA0B;MAChCC,OAAO,EAAE;QACPC,WAAW,EAAEN,OAAO,oBAAPA,OAAO,CAAEM,WAAW;QACjCR,IAAI,EAAEA,IAAI,8BAAQA,IAAI;UAAES,YAAY,EAAEP,OAAO,oBAAPA,OAAO,CAAEO;QAAY,KAAK,IAAI;QACpER;MACF;IACF,CAAC,CAAC;EACJ,CAAC,EAAE,CAACF,GAAG,CAAC,CAAC;AACX"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export declare enum EnvVariables {
|
|
2
|
+
/**
|
|
3
|
+
* The AppUrl is to tell Frontegg your application's app url
|
|
4
|
+
* for generating cookies and proxy http requests
|
|
5
|
+
*/
|
|
6
|
+
FRONTEGG_APP_URL = "FRONTEGG_APP_URL",
|
|
7
|
+
/**
|
|
8
|
+
* The Frontegg domain is your unique URL to connect to the Frontegg gateway, get it by visit:
|
|
9
|
+
* - For Dev environment [visit](https://portal.frontegg.com/development/settings/domains)
|
|
10
|
+
* - For Prod environment [visit](https://portal.frontegg.com/production/settings/domains)
|
|
11
|
+
*/
|
|
12
|
+
FRONTEGG_BASE_URL = "FRONTEGG_BASE_URL",
|
|
13
|
+
/**
|
|
14
|
+
* The Frontegg test domain used for testing proxy middleware
|
|
15
|
+
* @private for Frontegg
|
|
16
|
+
*/
|
|
17
|
+
FRONTEGG_TEST_URL = "FRONTEGG_TEST_URL",
|
|
18
|
+
/**
|
|
19
|
+
* Your Frontegg application's Client ID, get it by visit:
|
|
20
|
+
* - For Dev environment [visit](https://portal.frontegg.com/development/settings/general)
|
|
21
|
+
* - For Prod environment [visit](https://portal.frontegg.com/production/settings/general)
|
|
22
|
+
*/
|
|
23
|
+
FRONTEGG_CLIENT_ID = "FRONTEGG_CLIENT_ID",
|
|
24
|
+
/**
|
|
25
|
+
* The stateless session encryption password, used to encrypt
|
|
26
|
+
* JWT before sending it to the client side.
|
|
27
|
+
*
|
|
28
|
+
* For quick password generation use the following command:
|
|
29
|
+
*
|
|
30
|
+
* ```sh
|
|
31
|
+
* node -e "console.log(crypto.randomBytes(32).toString('hex'))"
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
FRONTEGG_ENCRYPTION_PASSWORD = "FRONTEGG_ENCRYPTION_PASSWORD",
|
|
35
|
+
/**
|
|
36
|
+
* The JWT public key generated by frontegg, to verify JWT before create session,
|
|
37
|
+
* get it by visit: https://[YOUR_FRONTEGG_FOMAIN]/.well-known/jwks.json.
|
|
38
|
+
*
|
|
39
|
+
* Then: Copy and Paste the first key from the response:
|
|
40
|
+
* {keys: [{__KEY__}]}
|
|
41
|
+
*/
|
|
42
|
+
FRONTEGG_JWT_PUBLIC_KEY = "FRONTEGG_JWT_PUBLIC_KEY",
|
|
43
|
+
/**
|
|
44
|
+
* The stateless cookie name for storing the encrypted JWT
|
|
45
|
+
* value as session cookies for supporting getServerSideProps and ServerComponents
|
|
46
|
+
*/
|
|
47
|
+
FRONTEGG_COOKIE_NAME = "FRONTEGG_COOKIE_NAME",
|
|
48
|
+
/**
|
|
49
|
+
* This Env variable assign automatically when deploying you Next.js application
|
|
50
|
+
* to Vercel deployments service, and will be used to detect to dynamically configure
|
|
51
|
+
* the {@link EnvVariables.FRONTEGG_APP_URL}
|
|
52
|
+
*
|
|
53
|
+
* @see [Vercel Environment Variables](https://vercel.com/docs/concepts/projects/environment-variables#system-environment-variables)
|
|
54
|
+
*/
|
|
55
|
+
VERCEL = "VERCEL",
|
|
56
|
+
VERCEL_URL = "VERCEL_URL"
|
|
57
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EnvVariables = void 0;
|
|
7
|
+
let EnvVariables;
|
|
8
|
+
exports.EnvVariables = EnvVariables;
|
|
9
|
+
(function (EnvVariables) {
|
|
10
|
+
EnvVariables["FRONTEGG_APP_URL"] = "FRONTEGG_APP_URL";
|
|
11
|
+
EnvVariables["FRONTEGG_BASE_URL"] = "FRONTEGG_BASE_URL";
|
|
12
|
+
EnvVariables["FRONTEGG_TEST_URL"] = "FRONTEGG_TEST_URL";
|
|
13
|
+
EnvVariables["FRONTEGG_CLIENT_ID"] = "FRONTEGG_CLIENT_ID";
|
|
14
|
+
EnvVariables["FRONTEGG_ENCRYPTION_PASSWORD"] = "FRONTEGG_ENCRYPTION_PASSWORD";
|
|
15
|
+
EnvVariables["FRONTEGG_JWT_PUBLIC_KEY"] = "FRONTEGG_JWT_PUBLIC_KEY";
|
|
16
|
+
EnvVariables["FRONTEGG_COOKIE_NAME"] = "FRONTEGG_COOKIE_NAME";
|
|
17
|
+
EnvVariables["VERCEL"] = "VERCEL";
|
|
18
|
+
EnvVariables["VERCEL_URL"] = "VERCEL_URL";
|
|
19
|
+
})(EnvVariables || (exports.EnvVariables = EnvVariables = {}));
|
|
20
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","names":["EnvVariables"],"sources":["../../../../packages/nextjs/src/config/constants.ts"],"sourcesContent":["export enum EnvVariables {\n /**\n * The AppUrl is to tell Frontegg your application's app url\n * for generating cookies and proxy http requests\n */\n FRONTEGG_APP_URL = 'FRONTEGG_APP_URL',\n /**\n * The Frontegg domain is your unique URL to connect to the Frontegg gateway, get it by visit:\n * - For Dev environment [visit](https://portal.frontegg.com/development/settings/domains)\n * - For Prod environment [visit](https://portal.frontegg.com/production/settings/domains)\n */\n FRONTEGG_BASE_URL = 'FRONTEGG_BASE_URL',\n /**\n * The Frontegg test domain used for testing proxy middleware\n * @private for Frontegg\n */\n FRONTEGG_TEST_URL = 'FRONTEGG_TEST_URL',\n\n /**\n * Your Frontegg application's Client ID, get it by visit:\n * - For Dev environment [visit](https://portal.frontegg.com/development/settings/general)\n * - For Prod environment [visit](https://portal.frontegg.com/production/settings/general)\n */\n FRONTEGG_CLIENT_ID = 'FRONTEGG_CLIENT_ID',\n\n /**\n * The stateless session encryption password, used to encrypt\n * JWT before sending it to the client side.\n *\n * For quick password generation use the following command:\n *\n * ```sh\n * node -e \"console.log(crypto.randomBytes(32).toString('hex'))\"\n * ```\n */\n FRONTEGG_ENCRYPTION_PASSWORD = 'FRONTEGG_ENCRYPTION_PASSWORD',\n\n /**\n * The JWT public key generated by frontegg, to verify JWT before create session,\n * get it by visit: https://[YOUR_FRONTEGG_FOMAIN]/.well-known/jwks.json.\n *\n * Then: Copy and Paste the first key from the response:\n * {keys: [{__KEY__}]}\n */\n FRONTEGG_JWT_PUBLIC_KEY = 'FRONTEGG_JWT_PUBLIC_KEY',\n\n /**\n * The stateless cookie name for storing the encrypted JWT\n * value as session cookies for supporting getServerSideProps and ServerComponents\n */\n FRONTEGG_COOKIE_NAME = 'FRONTEGG_COOKIE_NAME',\n\n /**\n * This Env variable assign automatically when deploying you Next.js application\n * to Vercel deployments service, and will be used to detect to dynamically configure\n * the {@link EnvVariables.FRONTEGG_APP_URL}\n *\n * @see [Vercel Environment Variables](https://vercel.com/docs/concepts/projects/environment-variables#system-environment-variables)\n */\n VERCEL = 'VERCEL',\n VERCEL_URL = 'VERCEL_URL',\n}\n"],"mappings":";;;;;;IAAYA,YAAY;AAAA;AAAA,WAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;AAAA,GAAZA,YAAY,4BAAZA,YAAY"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PasswordsMap } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Return environment variable's value.
|
|
4
|
+
* @throws {@link FronteggEnvNotFound} if not exists
|
|
5
|
+
* @param name
|
|
6
|
+
*/
|
|
7
|
+
export declare const getEnv: (name: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Return environment variable's value with default if not exists
|
|
10
|
+
* @param {string} name - the name from environment variable {@link EnvVariables}
|
|
11
|
+
* @param {optional string} defaultValue - default value if not exists
|
|
12
|
+
*/
|
|
13
|
+
export declare const getEnvOrDefault: <T>(name: string, defaultValue: T) => string | T;
|
|
14
|
+
/**
|
|
15
|
+
* extract hostname from appUrl for session cookie creation
|
|
16
|
+
* @param {string} appUrl - The generated appUrl
|
|
17
|
+
*/
|
|
18
|
+
export declare const generateCookieDomain: (appUrl: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Create passwordMap if from {@link EnvVariables.FRONTEGG_ENCRYPTION_PASSWORD}
|
|
21
|
+
* @param {string} password - encryption password
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalizeStringPasswordToMap(password: string | PasswordsMap): PasswordsMap;
|
|
24
|
+
/**
|
|
25
|
+
* Check if the Next.js application running on Vercel Deployment Service
|
|
26
|
+
* and calculate the appUrl based on Vercel Environment variables.
|
|
27
|
+
*/
|
|
28
|
+
export declare function generateAppUrl(): string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateAppUrl = generateAppUrl;
|
|
7
|
+
exports.getEnvOrDefault = exports.getEnv = exports.generateCookieDomain = void 0;
|
|
8
|
+
exports.normalizeStringPasswordToMap = normalizeStringPasswordToMap;
|
|
9
|
+
var _errors = require("../utils/errors");
|
|
10
|
+
var _constants = require("./constants");
|
|
11
|
+
/**
|
|
12
|
+
* Return environment variable's value.
|
|
13
|
+
* @throws {@link FronteggEnvNotFound} if not exists
|
|
14
|
+
* @param name
|
|
15
|
+
*/
|
|
16
|
+
const getEnv = name => {
|
|
17
|
+
const value = process.env[name];
|
|
18
|
+
if (!value) {
|
|
19
|
+
throw new _errors.FronteggEnvNotFound(name);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Return environment variable's value with default if not exists
|
|
26
|
+
* @param {string} name - the name from environment variable {@link EnvVariables}
|
|
27
|
+
* @param {optional string} defaultValue - default value if not exists
|
|
28
|
+
*/
|
|
29
|
+
exports.getEnv = getEnv;
|
|
30
|
+
const getEnvOrDefault = (name, defaultValue) => {
|
|
31
|
+
try {
|
|
32
|
+
return getEnv(name);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
return defaultValue;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* extract hostname from appUrl for session cookie creation
|
|
40
|
+
* @param {string} appUrl - The generated appUrl
|
|
41
|
+
*/
|
|
42
|
+
exports.getEnvOrDefault = getEnvOrDefault;
|
|
43
|
+
const generateCookieDomain = appUrl => {
|
|
44
|
+
try {
|
|
45
|
+
const url = new URL(appUrl);
|
|
46
|
+
return url.hostname.replace(/:(\d)+$/, '');
|
|
47
|
+
} catch (e) {
|
|
48
|
+
throw new _errors.InvalidFronteggEnv(_constants.EnvVariables.FRONTEGG_APP_URL, 'Valid URL');
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create passwordMap if from {@link EnvVariables.FRONTEGG_ENCRYPTION_PASSWORD}
|
|
54
|
+
* @param {string} password - encryption password
|
|
55
|
+
*/
|
|
56
|
+
exports.generateCookieDomain = generateCookieDomain;
|
|
57
|
+
function normalizeStringPasswordToMap(password) {
|
|
58
|
+
return typeof password === 'string' ? {
|
|
59
|
+
1: password
|
|
60
|
+
} : password;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Check if the Next.js application running on Vercel Deployment Service
|
|
65
|
+
* and calculate the appUrl based on Vercel Environment variables.
|
|
66
|
+
*/
|
|
67
|
+
function generateAppUrl() {
|
|
68
|
+
const appUrlEnv = getEnvOrDefault(_constants.EnvVariables.FRONTEGG_APP_URL, undefined);
|
|
69
|
+
const isVercel = getEnvOrDefault(_constants.EnvVariables.VERCEL, undefined) != undefined;
|
|
70
|
+
const vercelUrl = getEnvOrDefault(_constants.EnvVariables.VERCEL_URL, undefined);
|
|
71
|
+
let appUrl;
|
|
72
|
+
if (appUrlEnv) {
|
|
73
|
+
appUrl = appUrlEnv;
|
|
74
|
+
} else if (isVercel && vercelUrl) {
|
|
75
|
+
appUrl = vercelUrl;
|
|
76
|
+
}
|
|
77
|
+
if (!appUrl) {
|
|
78
|
+
if (isVercel) {
|
|
79
|
+
throw new _errors.FronteggEnvNotFound(_constants.EnvVariables.VERCEL, _constants.EnvVariables.VERCEL_URL);
|
|
80
|
+
} else {
|
|
81
|
+
throw new _errors.FronteggEnvNotFound(_constants.EnvVariables.FRONTEGG_APP_URL);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* In some cases the {@link EnvVariables.VERCEL_URL} value does not
|
|
87
|
+
* include the URL protocol, bellow code to verify that the appUrl
|
|
88
|
+
* must have a valid http protocol
|
|
89
|
+
*/
|
|
90
|
+
if (!appUrl.startsWith('http')) {
|
|
91
|
+
// noinspection HttpUrlsUsage
|
|
92
|
+
const protocol = appUrl.startsWith('localhost') ? 'http://' : 'https://';
|
|
93
|
+
appUrl = `${protocol}${appUrl}`;
|
|
94
|
+
}
|
|
95
|
+
return appUrl;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","names":["getEnv","name","value","process","env","FronteggEnvNotFound","getEnvOrDefault","defaultValue","e","generateCookieDomain","appUrl","url","URL","hostname","replace","InvalidFronteggEnv","EnvVariables","FRONTEGG_APP_URL","normalizeStringPasswordToMap","password","generateAppUrl","appUrlEnv","undefined","isVercel","VERCEL","vercelUrl","VERCEL_URL","startsWith","protocol"],"sources":["../../../../packages/nextjs/src/config/helpers.ts"],"sourcesContent":["import { InvalidFronteggEnv, FronteggEnvNotFound } from '../utils/errors';\nimport { PasswordsMap } from './types';\nimport { EnvVariables } from './constants';\n\n/**\n * Return environment variable's value.\n * @throws {@link FronteggEnvNotFound} if not exists\n * @param name\n */\nexport const getEnv = (name: string): string => {\n const value = process.env[name];\n if (!value) {\n throw new FronteggEnvNotFound(name);\n }\n return value;\n};\n\n/**\n * Return environment variable's value with default if not exists\n * @param {string} name - the name from environment variable {@link EnvVariables}\n * @param {optional string} defaultValue - default value if not exists\n */\nexport const getEnvOrDefault = <T>(name: string, defaultValue: T): string | T => {\n try {\n return getEnv(name);\n } catch (e) {\n return defaultValue;\n }\n};\n\n/**\n * extract hostname from appUrl for session cookie creation\n * @param {string} appUrl - The generated appUrl\n */\nexport const generateCookieDomain = (appUrl: string): string => {\n try {\n const url = new URL(appUrl);\n return url.hostname.replace(/:(\\d)+$/, '');\n } catch (e) {\n throw new InvalidFronteggEnv(EnvVariables.FRONTEGG_APP_URL, 'Valid URL');\n }\n};\n\n/**\n * Create passwordMap if from {@link EnvVariables.FRONTEGG_ENCRYPTION_PASSWORD}\n * @param {string} password - encryption password\n */\nexport function normalizeStringPasswordToMap(password: string | PasswordsMap): PasswordsMap {\n return typeof password === 'string' ? { 1: password } : password;\n}\n\n/**\n * Check if the Next.js application running on Vercel Deployment Service\n * and calculate the appUrl based on Vercel Environment variables.\n */\nexport function generateAppUrl() {\n const appUrlEnv = getEnvOrDefault(EnvVariables.FRONTEGG_APP_URL, undefined);\n const isVercel = getEnvOrDefault(EnvVariables.VERCEL, undefined) != undefined;\n const vercelUrl = getEnvOrDefault(EnvVariables.VERCEL_URL, undefined);\n\n let appUrl: string | undefined;\n if (appUrlEnv) {\n appUrl = appUrlEnv;\n } else if (isVercel && vercelUrl) {\n appUrl = vercelUrl;\n }\n\n if (!appUrl) {\n if (isVercel) {\n throw new FronteggEnvNotFound(EnvVariables.VERCEL, EnvVariables.VERCEL_URL);\n } else {\n throw new FronteggEnvNotFound(EnvVariables.FRONTEGG_APP_URL);\n }\n }\n\n /**\n * In some cases the {@link EnvVariables.VERCEL_URL} value does not\n * include the URL protocol, bellow code to verify that the appUrl\n * must have a valid http protocol\n */\n if (!appUrl.startsWith('http')) {\n // noinspection HttpUrlsUsage\n const protocol = appUrl.startsWith('localhost') ? 'http://' : 'https://';\n appUrl = `${protocol}${appUrl}`;\n }\n\n return appUrl;\n}\n"],"mappings":";;;;;;;;AAAA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACO,MAAMA,MAAM,GAAIC,IAAY,IAAa;EAC9C,MAAMC,KAAK,GAAGC,OAAO,CAACC,GAAG,CAACH,IAAI,CAAC;EAC/B,IAAI,CAACC,KAAK,EAAE;IACV,MAAM,IAAIG,2BAAmB,CAACJ,IAAI,CAAC;EACrC;EACA,OAAOC,KAAK;AACd,CAAC;;AAED;AACA;AACA;AACA;AACA;AAJA;AAKO,MAAMI,eAAe,GAAG,CAAIL,IAAY,EAAEM,YAAe,KAAiB;EAC/E,IAAI;IACF,OAAOP,MAAM,CAACC,IAAI,CAAC;EACrB,CAAC,CAAC,OAAOO,CAAC,EAAE;IACV,OAAOD,YAAY;EACrB;AACF,CAAC;;AAED;AACA;AACA;AACA;AAHA;AAIO,MAAME,oBAAoB,GAAIC,MAAc,IAAa;EAC9D,IAAI;IACF,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAACF,MAAM,CAAC;IAC3B,OAAOC,GAAG,CAACE,QAAQ,CAACC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;EAC5C,CAAC,CAAC,OAAON,CAAC,EAAE;IACV,MAAM,IAAIO,0BAAkB,CAACC,uBAAY,CAACC,gBAAgB,EAAE,WAAW,CAAC;EAC1E;AACF,CAAC;;AAED;AACA;AACA;AACA;AAHA;AAIO,SAASC,4BAA4B,CAACC,QAA+B,EAAgB;EAC1F,OAAO,OAAOA,QAAQ,KAAK,QAAQ,GAAG;IAAE,CAAC,EAAEA;EAAS,CAAC,GAAGA,QAAQ;AAClE;;AAEA;AACA;AACA;AACA;AACO,SAASC,cAAc,GAAG;EAC/B,MAAMC,SAAS,GAAGf,eAAe,CAACU,uBAAY,CAACC,gBAAgB,EAAEK,SAAS,CAAC;EAC3E,MAAMC,QAAQ,GAAGjB,eAAe,CAACU,uBAAY,CAACQ,MAAM,EAAEF,SAAS,CAAC,IAAIA,SAAS;EAC7E,MAAMG,SAAS,GAAGnB,eAAe,CAACU,uBAAY,CAACU,UAAU,EAAEJ,SAAS,CAAC;EAErE,IAAIZ,MAA0B;EAC9B,IAAIW,SAAS,EAAE;IACbX,MAAM,GAAGW,SAAS;EACpB,CAAC,MAAM,IAAIE,QAAQ,IAAIE,SAAS,EAAE;IAChCf,MAAM,GAAGe,SAAS;EACpB;EAEA,IAAI,CAACf,MAAM,EAAE;IACX,IAAIa,QAAQ,EAAE;MACZ,MAAM,IAAIlB,2BAAmB,CAACW,uBAAY,CAACQ,MAAM,EAAER,uBAAY,CAACU,UAAU,CAAC;IAC7E,CAAC,MAAM;MACL,MAAM,IAAIrB,2BAAmB,CAACW,uBAAY,CAACC,gBAAgB,CAAC;IAC9D;EACF;;EAEA;AACF;AACA;AACA;AACA;EACE,IAAI,CAACP,MAAM,CAACiB,UAAU,CAAC,MAAM,CAAC,EAAE;IAC9B;IACA,MAAMC,QAAQ,GAAGlB,MAAM,CAACiB,UAAU,CAAC,WAAW,CAAC,GAAG,SAAS,GAAG,UAAU;IACxEjB,MAAM,GAAI,GAAEkB,QAAS,GAAElB,MAAO,EAAC;EACjC;EAEA,OAAOA,MAAM;AACf"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AuthPageRoutes } from '@frontegg/redux-store';
|
|
2
|
+
import { FronteggAppOptions } from '@frontegg/types';
|
|
3
|
+
import { AppEnvConfig, PasswordsMap } from './types';
|
|
4
|
+
declare class Config {
|
|
5
|
+
authRoutes: Partial<AuthPageRoutes>;
|
|
6
|
+
fronteggAppOptions: Partial<FronteggAppOptions>;
|
|
7
|
+
constructor();
|
|
8
|
+
get appUrl(): string;
|
|
9
|
+
get testUrl(): string | undefined;
|
|
10
|
+
get baseUrl(): string;
|
|
11
|
+
get baseUrlHost(): string;
|
|
12
|
+
get clientId(): string;
|
|
13
|
+
get jwtPublicKeyJson(): string | undefined;
|
|
14
|
+
get cookieName(): string;
|
|
15
|
+
get cookieDomain(): string;
|
|
16
|
+
private validatePassword;
|
|
17
|
+
get password(): PasswordsMap;
|
|
18
|
+
get isSSL(): boolean;
|
|
19
|
+
get isHostedLogin(): boolean;
|
|
20
|
+
get appEnvConfig(): AppEnvConfig;
|
|
21
|
+
}
|
|
22
|
+
export { EnvVariables } from './constants';
|
|
23
|
+
declare const _default: Config;
|
|
24
|
+
export default _default;
|
package/config/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "EnvVariables", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _constants.EnvVariables;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
exports.default = void 0;
|
|
13
|
+
var _helpers = require("./helpers");
|
|
14
|
+
var _constants = require("./constants");
|
|
15
|
+
var _errors = require("../utils/errors");
|
|
16
|
+
const setupEnvVariables = {
|
|
17
|
+
FRONTEGG_APP_URL: process.env.FRONTEGG_APP_URL,
|
|
18
|
+
FRONTEGG_BASE_URL: process.env.FRONTEGG_BASE_URL,
|
|
19
|
+
FRONTEGG_TEST_URL: process.env.FRONTEGG_TEST_URL,
|
|
20
|
+
FRONTEGG_CLIENT_ID: process.env.FRONTEGG_CLIENT_ID,
|
|
21
|
+
FRONTEGG_ENCRYPTION_PASSWORD: process.env.FRONTEGG_ENCRYPTION_PASSWORD,
|
|
22
|
+
FRONTEGG_COOKIE_NAME: process.env.FRONTEGG_COOKIE_NAME,
|
|
23
|
+
FRONTEGG_JWT_PUBLIC_KEY: process.env.FRONTEGG_JWT_PUBLIC_KEY,
|
|
24
|
+
VERCEL: process.env.VERCEL,
|
|
25
|
+
VERCEL_URL: process.env.VERCEL_URL
|
|
26
|
+
};
|
|
27
|
+
class Config {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.authRoutes = {};
|
|
30
|
+
this.fronteggAppOptions = {};
|
|
31
|
+
if (typeof window === 'undefined') {
|
|
32
|
+
this.validatePassword();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
get appUrl() {
|
|
36
|
+
return (0, _helpers.generateAppUrl)();
|
|
37
|
+
}
|
|
38
|
+
get testUrl() {
|
|
39
|
+
return (0, _helpers.getEnvOrDefault)(_constants.EnvVariables.FRONTEGG_TEST_URL, setupEnvVariables.FRONTEGG_TEST_URL);
|
|
40
|
+
}
|
|
41
|
+
get baseUrl() {
|
|
42
|
+
var _getEnv;
|
|
43
|
+
return (_getEnv = (0, _helpers.getEnv)(_constants.EnvVariables.FRONTEGG_BASE_URL)) != null ? _getEnv : setupEnvVariables.FRONTEGG_BASE_URL;
|
|
44
|
+
}
|
|
45
|
+
get baseUrlHost() {
|
|
46
|
+
return new URL(this.baseUrl).hostname;
|
|
47
|
+
}
|
|
48
|
+
get clientId() {
|
|
49
|
+
var _getEnv2;
|
|
50
|
+
return (_getEnv2 = (0, _helpers.getEnv)(_constants.EnvVariables.FRONTEGG_CLIENT_ID)) != null ? _getEnv2 : setupEnvVariables.FRONTEGG_CLIENT_ID;
|
|
51
|
+
}
|
|
52
|
+
get jwtPublicKeyJson() {
|
|
53
|
+
return (0, _helpers.getEnv)(_constants.EnvVariables.FRONTEGG_JWT_PUBLIC_KEY);
|
|
54
|
+
}
|
|
55
|
+
get cookieName() {
|
|
56
|
+
var _setupEnvVariables$FR;
|
|
57
|
+
const cookieNameEnv = (0, _helpers.getEnvOrDefault)(_constants.EnvVariables.FRONTEGG_COOKIE_NAME, (_setupEnvVariables$FR = setupEnvVariables.FRONTEGG_COOKIE_NAME) != null ? _setupEnvVariables$FR : 'fe_session');
|
|
58
|
+
return `${cookieNameEnv}-${this.clientId.replace(/-/g, '')}`;
|
|
59
|
+
}
|
|
60
|
+
get cookieDomain() {
|
|
61
|
+
return (0, _helpers.generateCookieDomain)(this.appUrl);
|
|
62
|
+
}
|
|
63
|
+
validatePassword() {
|
|
64
|
+
const passwordMaps = this.password;
|
|
65
|
+
for (let key of Object.keys(passwordMaps)) {
|
|
66
|
+
const password = passwordMaps[key];
|
|
67
|
+
if (!password.match(/[0-9A-Fa-f]{6}/g) || password.length !== 64) {
|
|
68
|
+
throw new _errors.InvalidFronteggEnv(_constants.EnvVariables.FRONTEGG_ENCRYPTION_PASSWORD, `Hex string.\n\nFor quick password generation use the following command:\nnode -e "console.log(crypto.randomBytes(32).toString('hex'))"`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
get password() {
|
|
73
|
+
var _getEnv3;
|
|
74
|
+
const encryptionPasswordEnv = (_getEnv3 = (0, _helpers.getEnv)(_constants.EnvVariables.FRONTEGG_ENCRYPTION_PASSWORD)) != null ? _getEnv3 : setupEnvVariables.FRONTEGG_ENCRYPTION_PASSWORD;
|
|
75
|
+
return (0, _helpers.normalizeStringPasswordToMap)(encryptionPasswordEnv);
|
|
76
|
+
}
|
|
77
|
+
get isSSL() {
|
|
78
|
+
return new URL(this.appUrl).protocol === 'https:';
|
|
79
|
+
}
|
|
80
|
+
get isHostedLogin() {
|
|
81
|
+
var _this$fronteggAppOpti;
|
|
82
|
+
return (_this$fronteggAppOpti = this.fronteggAppOptions.hostedLoginBox) != null ? _this$fronteggAppOpti : false;
|
|
83
|
+
}
|
|
84
|
+
get appEnvConfig() {
|
|
85
|
+
return {
|
|
86
|
+
envAppUrl: this.appUrl,
|
|
87
|
+
envBaseUrl: this.baseUrl,
|
|
88
|
+
envClientId: this.clientId
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
var _default = new Config();
|
|
93
|
+
exports.default = _default;
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["setupEnvVariables","FRONTEGG_APP_URL","process","env","FRONTEGG_BASE_URL","FRONTEGG_TEST_URL","FRONTEGG_CLIENT_ID","FRONTEGG_ENCRYPTION_PASSWORD","FRONTEGG_COOKIE_NAME","FRONTEGG_JWT_PUBLIC_KEY","VERCEL","VERCEL_URL","Config","constructor","authRoutes","fronteggAppOptions","window","validatePassword","appUrl","generateAppUrl","testUrl","getEnvOrDefault","EnvVariables","baseUrl","getEnv","baseUrlHost","URL","hostname","clientId","jwtPublicKeyJson","cookieName","cookieNameEnv","replace","cookieDomain","generateCookieDomain","passwordMaps","password","key","Object","keys","match","length","InvalidFronteggEnv","encryptionPasswordEnv","normalizeStringPasswordToMap","isSSL","protocol","isHostedLogin","hostedLoginBox","appEnvConfig","envAppUrl","envBaseUrl","envClientId"],"sources":["../../../../packages/nextjs/src/config/index.ts"],"sourcesContent":["import { AuthPageRoutes } from '@frontegg/redux-store';\nimport { FronteggAppOptions } from '@frontegg/types';\nimport { AppEnvConfig, PasswordsMap } from './types';\nimport { generateAppUrl, generateCookieDomain, getEnv, getEnvOrDefault, normalizeStringPasswordToMap } from './helpers';\nimport { EnvVariables } from './constants';\nimport { InvalidFronteggEnv } from '../utils/errors';\n\nconst setupEnvVariables = {\n FRONTEGG_APP_URL: process.env.FRONTEGG_APP_URL,\n FRONTEGG_BASE_URL: process.env.FRONTEGG_BASE_URL,\n FRONTEGG_TEST_URL: process.env.FRONTEGG_TEST_URL,\n FRONTEGG_CLIENT_ID: process.env.FRONTEGG_CLIENT_ID,\n FRONTEGG_ENCRYPTION_PASSWORD: process.env.FRONTEGG_ENCRYPTION_PASSWORD,\n FRONTEGG_COOKIE_NAME: process.env.FRONTEGG_COOKIE_NAME,\n FRONTEGG_JWT_PUBLIC_KEY: process.env.FRONTEGG_JWT_PUBLIC_KEY,\n VERCEL: process.env.VERCEL,\n VERCEL_URL: process.env.VERCEL_URL,\n};\n\nclass Config {\n public authRoutes: Partial<AuthPageRoutes> = {};\n public fronteggAppOptions: Partial<FronteggAppOptions> = {};\n constructor() {\n if (typeof window === 'undefined') {\n this.validatePassword();\n }\n }\n\n get appUrl(): string {\n return generateAppUrl();\n }\n\n get testUrl(): string | undefined {\n return getEnvOrDefault(EnvVariables.FRONTEGG_TEST_URL, setupEnvVariables.FRONTEGG_TEST_URL);\n }\n\n get baseUrl(): string {\n return getEnv(EnvVariables.FRONTEGG_BASE_URL) ?? setupEnvVariables.FRONTEGG_BASE_URL;\n }\n\n get baseUrlHost(): string {\n return new URL(this.baseUrl).hostname;\n }\n\n get clientId(): string {\n return getEnv(EnvVariables.FRONTEGG_CLIENT_ID) ?? setupEnvVariables.FRONTEGG_CLIENT_ID;\n }\n\n get jwtPublicKeyJson(): string | undefined {\n return getEnv(EnvVariables.FRONTEGG_JWT_PUBLIC_KEY);\n }\n\n get cookieName(): string {\n const cookieNameEnv = getEnvOrDefault(\n EnvVariables.FRONTEGG_COOKIE_NAME,\n setupEnvVariables.FRONTEGG_COOKIE_NAME ?? 'fe_session'\n );\n return `${cookieNameEnv}-${this.clientId.replace(/-/g, '')}`;\n }\n\n get cookieDomain(): string {\n return generateCookieDomain(this.appUrl);\n }\n\n private validatePassword() {\n const passwordMaps = this.password;\n for (let key of Object.keys(passwordMaps)) {\n const password = passwordMaps[key];\n if (!password.match(/[0-9A-Fa-f]{6}/g) || password.length !== 64) {\n throw new InvalidFronteggEnv(\n EnvVariables.FRONTEGG_ENCRYPTION_PASSWORD,\n `Hex string.\\n\\nFor quick password generation use the following command:\\nnode -e \"console.log(crypto.randomBytes(32).toString('hex'))\"`\n );\n }\n }\n }\n get password(): PasswordsMap {\n const encryptionPasswordEnv =\n getEnv(EnvVariables.FRONTEGG_ENCRYPTION_PASSWORD) ?? setupEnvVariables.FRONTEGG_ENCRYPTION_PASSWORD;\n\n return normalizeStringPasswordToMap(encryptionPasswordEnv);\n }\n\n get isSSL(): boolean {\n return new URL(this.appUrl).protocol === 'https:';\n }\n\n get isHostedLogin(): boolean {\n return this.fronteggAppOptions.hostedLoginBox ?? false;\n }\n\n get appEnvConfig(): AppEnvConfig {\n return {\n envAppUrl: this.appUrl,\n envBaseUrl: this.baseUrl,\n envClientId: this.clientId,\n };\n }\n}\n\nexport { EnvVariables } from './constants';\nexport default new Config();\n"],"mappings":"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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PasswordMap used for JWT encryption, you can create multiple passwords
|
|
3
|
+
* to be used for encrypting session cookie as round-robin strategy.
|
|
4
|
+
*/
|
|
5
|
+
export type PasswordsMap = {
|
|
6
|
+
[id: string]: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* PropTypes passed by FronteggProvider to the ClientSide Frontegg components.
|
|
10
|
+
*/
|
|
11
|
+
export interface AppEnvConfig {
|
|
12
|
+
/** {@link EnvVariables.FRONTEGG_APP_URL} */
|
|
13
|
+
envAppUrl: string;
|
|
14
|
+
/** {@link EnvVariables.FRONTEGG_BASE_URL} */
|
|
15
|
+
envBaseUrl: string;
|
|
16
|
+
/** {@link EnvVariables.FRONTEGG_CLIENT_ID} */
|
|
17
|
+
envClientId: string;
|
|
18
|
+
}
|
package/config/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../packages/nextjs/src/config/types.ts"],"sourcesContent":["/**\n * PasswordMap used for JWT encryption, you can create multiple passwords\n * to be used for encrypting session cookie as round-robin strategy.\n */\nexport type PasswordsMap = { [id: string]: string };\n\n/**\n * PropTypes passed by FronteggProvider to the ClientSide Frontegg components.\n */\nexport interface AppEnvConfig {\n /** {@link EnvVariables.FRONTEGG_APP_URL} */\n envAppUrl: string;\n /** {@link EnvVariables.FRONTEGG_BASE_URL} */\n envBaseUrl: string;\n /** {@link EnvVariables.FRONTEGG_CLIENT_ID} */\n envClientId: string;\n}\n"],"mappings":""}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { IncomingMessage } from 'http';
|
|
2
|
+
import { FronteggNextJSSession } from '../types';
|
|
3
|
+
export declare const getSessionOnEdge: (req: IncomingMessage | Request) => Promise<FronteggNextJSSession | undefined>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getSessionOnEdge = void 0;
|
|
8
|
+
var _cookies = _interopRequireDefault(require("../utils/cookies"));
|
|
9
|
+
var _createSession = _interopRequireDefault(require("../utils/createSession"));
|
|
10
|
+
var _encryptionEdge = _interopRequireDefault(require("../utils/encryption-edge"));
|
|
11
|
+
const getSessionOnEdge = req => {
|
|
12
|
+
const cookies = _cookies.default.getSessionCookieFromRequest(req);
|
|
13
|
+
return (0, _createSession.default)(cookies, _encryptionEdge.default);
|
|
14
|
+
};
|
|
15
|
+
exports.getSessionOnEdge = getSessionOnEdge;
|
|
16
|
+
//# sourceMappingURL=getSessionOnEdge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSessionOnEdge.js","names":["getSessionOnEdge","req","cookies","CookieManager","getSessionCookieFromRequest","createSession","encryptionEdge"],"sources":["../../../../packages/nextjs/src/edge/getSessionOnEdge.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\nimport { FronteggNextJSSession } from '../types';\nimport CookieManager from '../utils/cookies';\nimport createSession from '../utils/createSession';\nimport encryptionEdge from '../utils/encryption-edge';\n\nexport const getSessionOnEdge = (req: IncomingMessage | Request): Promise<FronteggNextJSSession | undefined> => {\n const cookies = CookieManager.getSessionCookieFromRequest(req);\n return createSession(cookies, encryptionEdge);\n};\n"],"mappings":";;;;;;;AAEA;AACA;AACA;AAEO,MAAMA,gBAAgB,GAAIC,GAA8B,IAAiD;EAC9G,MAAMC,OAAO,GAAGC,gBAAa,CAACC,2BAA2B,CAACH,GAAG,CAAC;EAC9D,OAAO,IAAAI,sBAAa,EAACH,OAAO,EAAEI,uBAAc,CAAC;AAC/C,CAAC;AAAC"}
|
package/edge/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from './getSessionOnEdge';
|
|
2
|
-
export * from './shouldBypassMiddleware';
|
|
1
|
+
export * from './getSessionOnEdge';
|
|
2
|
+
export * from './shouldBypassMiddleware';
|
|
3
|
+
export * from './redirectToLogin';
|
package/edge/index.js
CHANGED
|
@@ -1,64 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
import { unsealData } from 'iron-session/edge';
|
|
3
|
-
import { C as CookieManager, F as FronteggConfig } from '../CookieManager-e50dc144.js';
|
|
4
|
-
import { c as createGetSession } from '../createGetSession-2e1e4506.js';
|
|
5
|
-
import 'cookie';
|
|
6
|
-
import 'jose';
|
|
1
|
+
"use strict";
|
|
7
2
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var isStaticFiles = staticFilesRegex.test(pathname);
|
|
46
|
-
var isImageOptimization = imageOptimizationRegex.test(pathname);
|
|
47
|
-
var isHeaderRequests = headerRequestsRegex.test(pathname);
|
|
48
|
-
var isFronteggMiddleware = fronteggMiddlewareRegex.test(pathname);
|
|
49
|
-
var isFronteggRoutes = fronteggRoutesRegex.test(pathname);
|
|
50
|
-
if (isStaticFiles)
|
|
51
|
-
return _options.bypassStaticFiles;
|
|
52
|
-
if (isImageOptimization)
|
|
53
|
-
return _options.bypassImageOptimization;
|
|
54
|
-
if (isHeaderRequests)
|
|
55
|
-
return _options.bypassHeaderRequests;
|
|
56
|
-
if (isFronteggMiddleware)
|
|
57
|
-
return _options.bypassFronteggMiddleware;
|
|
58
|
-
if (isFronteggRoutes)
|
|
59
|
-
return _options.bypassFronteggRoutes;
|
|
60
|
-
return false;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export { getSession, shouldByPassMiddleware };
|
|
64
|
-
//# sourceMappingURL=index.js.map
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _getSessionOnEdge = require("./getSessionOnEdge");
|
|
7
|
+
Object.keys(_getSessionOnEdge).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _getSessionOnEdge[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _getSessionOnEdge[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _shouldBypassMiddleware = require("./shouldBypassMiddleware");
|
|
18
|
+
Object.keys(_shouldBypassMiddleware).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _shouldBypassMiddleware[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _shouldBypassMiddleware[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _redirectToLogin = require("./redirectToLogin");
|
|
29
|
+
Object.keys(_redirectToLogin).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _redirectToLogin[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _redirectToLogin[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
package/edge/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../packages/nextjs/src/edge/index.ts"],"sourcesContent":["export * from './getSessionOnEdge';\nexport * from './shouldBypassMiddleware';\nexport * from './redirectToLogin';\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.redirectToLogin = void 0;
|
|
7
|
+
var _server = require("next/server");
|
|
8
|
+
var _urls = require("../api/urls");
|
|
9
|
+
const redirectToLogin = pathname => {
|
|
10
|
+
const {
|
|
11
|
+
asUrl: loginUrl
|
|
12
|
+
} = (0, _urls.buildLoginRoute)(pathname);
|
|
13
|
+
return _server.NextResponse.redirect(loginUrl);
|
|
14
|
+
};
|
|
15
|
+
exports.redirectToLogin = redirectToLogin;
|
|
16
|
+
//# sourceMappingURL=redirectToLogin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToLogin.js","names":["redirectToLogin","pathname","asUrl","loginUrl","buildLoginRoute","NextResponse","redirect"],"sources":["../../../../packages/nextjs/src/edge/redirectToLogin.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { buildLoginRoute } from '../api/urls';\n\nexport const redirectToLogin = (pathname: string) => {\n const { asUrl: loginUrl } = buildLoginRoute(pathname);\n return NextResponse.redirect(loginUrl);\n};\n"],"mappings":";;;;;;AAAA;AACA;AAEO,MAAMA,eAAe,GAAIC,QAAgB,IAAK;EACnD,MAAM;IAAEC,KAAK,EAAEC;EAAS,CAAC,GAAG,IAAAC,qBAAe,EAACH,QAAQ,CAAC;EACrD,OAAOI,oBAAY,CAACC,QAAQ,CAACH,QAAQ,CAAC;AACxC,CAAC;AAAC"}
|