@frontegg/nextjs 6.7.20 → 6.7.21-alpha.4441481917
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 +10 -0
- package/README.md +19 -37
- package/api/index.d.ts +19 -0
- package/api/index.js +78 -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 +46 -0
- package/api/urls.js.map +1 -0
- package/api/utils.d.ts +46 -0
- package/api/utils.js +108 -0
- package/api/utils.js.map +1 -0
- package/app/ClientFronteggProvider.d.ts +3 -0
- package/app/ClientFronteggProvider.js +25 -0
- package/app/ClientFronteggProvider.js.map +1 -0
- package/app/FronteggAppProvider.d.ts +4 -0
- package/app/FronteggAppProvider.js +17 -0
- package/app/FronteggAppProvider.js.map +1 -0
- package/{client → app}/FronteggAppRouter.d.ts +11 -10
- package/app/FronteggAppRouter.js +31 -0
- package/app/FronteggAppRouter.js.map +1 -0
- package/app/helpers.d.ts +5 -0
- package/app/helpers.js +32 -0
- package/app/helpers.js.map +1 -0
- package/app/index.d.ts +4 -0
- package/app/index.js +4 -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 +6 -0
- package/common/AppContext.js.map +1 -0
- package/{AuthorizedContent.d.ts → common/AuthorizedContent.d.ts} +9 -8
- package/common/AuthorizedContent.js +48 -0
- package/common/AuthorizedContent.js.map +1 -0
- package/common/{client/FronteggBaseProvider.d.ts → FronteggBaseProvider.d.ts} +3 -3
- package/common/FronteggBaseProvider.js +67 -0
- package/common/FronteggBaseProvider.js.map +1 -0
- package/common/FronteggRouterBase.d.ts +9 -0
- package/common/FronteggRouterBase.js +42 -0
- package/common/FronteggRouterBase.js.map +1 -0
- package/common/helpers.d.ts +3 -9
- package/common/helpers.js +24 -0
- package/common/helpers.js.map +1 -0
- package/common/index.d.ts +4 -6
- package/common/index.js +5 -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 +24 -0
- package/common/useRequestAuthorizeSSR.js.map +1 -0
- package/config/constants.d.ts +57 -0
- package/config/constants.js +13 -0
- package/config/constants.js.map +1 -0
- package/config/helpers.d.ts +28 -0
- package/config/helpers.js +87 -0
- package/config/helpers.js.map +1 -0
- package/config/index.d.ts +24 -0
- package/config/index.js +82 -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 +2 -0
- package/config/types.js.map +1 -0
- package/edge/getSessionOnEdge.d.ts +3 -2
- package/edge/getSessionOnEdge.js +8 -0
- package/edge/getSessionOnEdge.js.map +1 -0
- package/edge/index.d.ts +3 -2
- package/edge/index.js +4 -64
- package/edge/index.js.map +1 -1
- package/edge/package.json +6 -0
- package/edge/redirectToLogin.d.ts +2 -0
- package/edge/redirectToLogin.js +9 -0
- package/edge/redirectToLogin.js.map +1 -0
- package/edge/shouldBypassMiddleware.d.ts +21 -7
- package/edge/shouldBypassMiddleware.js +42 -0
- package/edge/shouldBypassMiddleware.js.map +1 -0
- package/index.d.ts +7 -11
- package/index.js +13 -1401
- package/index.js.map +1 -1
- package/middleware/FronteggApiMiddleware.d.ts +8 -0
- package/middleware/FronteggApiMiddleware.js +28 -0
- package/middleware/FronteggApiMiddleware.js.map +1 -0
- package/middleware/FronteggProxy.d.ts +4 -0
- package/middleware/FronteggProxy.js +24 -0
- package/middleware/FronteggProxy.js.map +1 -0
- package/middleware/ProxyRequestCallback.d.ts +13 -0
- package/middleware/ProxyRequestCallback.js +48 -0
- package/middleware/ProxyRequestCallback.js.map +1 -0
- package/middleware/ProxyResponseCallback.d.ts +13 -0
- package/middleware/ProxyResponseCallback.js +103 -0
- package/middleware/ProxyResponseCallback.js.map +1 -0
- package/middleware/constants.d.ts +8 -0
- package/middleware/constants.js +9 -0
- package/middleware/constants.js.map +1 -0
- package/{common/FronteggProxy.d.ts → middleware/helpers.d.ts} +13 -26
- package/middleware/helpers.js +35 -0
- package/middleware/helpers.js.map +1 -0
- package/middleware/index.d.ts +23 -0
- package/middleware/index.js +24 -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 +22 -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 +76 -0
- package/no-ssr/FronteggProviderNoSSR.js.map +1 -0
- package/no-ssr/index.d.ts +2 -0
- package/no-ssr/index.js +2 -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 +24 -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 +38 -0
- package/pages/FronteggRouter/FronteggRouter.js.map +1 -0
- package/pages/FronteggRouter/index.d.ts +26 -0
- package/pages/FronteggRouter/index.js +27 -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 +31 -0
- package/pages/helpers.js.map +1 -0
- package/pages/index.d.ts +3 -0
- package/pages/index.js +4 -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 +2 -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 +2 -0
- package/pages/withFronteggApp/types.js.map +1 -0
- package/pages/withFronteggApp/withFronteggApp.d.ts +2 -0
- package/pages/withFronteggApp/withFronteggApp.js +62 -0
- package/pages/withFronteggApp/withFronteggApp.js.map +1 -0
- package/sdkVersion.d.ts +4 -4
- package/sdkVersion.js +4 -0
- package/sdkVersion.js.map +1 -0
- package/{common/types.d.ts → types/index.d.ts} +80 -74
- package/types/index.js +2 -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 +14 -0
- package/utils/common/constants.js.map +1 -0
- package/utils/common/index.d.ts +15 -0
- package/utils/common/index.js +26 -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 +8 -0
- package/utils/cookies/constants.js.map +1 -0
- package/utils/cookies/helpers.d.ts +25 -0
- package/utils/cookies/helpers.js +53 -0
- package/utils/cookies/helpers.js.map +1 -0
- package/utils/cookies/index.d.ts +45 -0
- package/utils/cookies/index.js +232 -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 +154 -0
- package/utils/cookies/serializer.js.map +1 -0
- package/utils/cookies/types.d.ts +31 -0
- package/utils/cookies/types.js +2 -0
- package/utils/cookies/types.js.map +1 -0
- package/utils/createSession/index.d.ts +2 -0
- package/utils/createSession/index.js +44 -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 +29 -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 +29 -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 +8 -0
- package/utils/errors/FronteggEnvNotFound.js.map +1 -0
- package/utils/errors/InvalidFronteggEnv.d.ts +3 -0
- package/utils/errors/InvalidFronteggEnv.js +8 -0
- package/utils/errors/InvalidFronteggEnv.js.map +1 -0
- package/utils/errors/index.d.ts +2 -0
- package/utils/errors/index.js +3 -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 +49 -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 +20 -0
- package/utils/fronteggLogger/constants.js.map +1 -0
- package/utils/fronteggLogger/index.d.ts +17 -0
- package/utils/fronteggLogger/index.js +61 -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 +100 -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 +53 -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 +69 -0
- package/utils/refreshAccessToken/helpers.js.map +1 -0
- package/utils/refreshAccessToken/index.d.ts +9 -0
- package/utils/refreshAccessToken/index.js +88 -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 +23 -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 +21 -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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## [6.7.21](https://github.com/frontegg/frontegg-nextjs/compare/v6.7.20...v6.7.21) (2023-3-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### NextJS Wrapper 6.7.21:
|
|
7
|
+
- FR-10654 - Prevent overriding default package.json file in dist folder
|
|
8
|
+
- FR-10654 - Add missing alpha version in pre-release script
|
|
9
|
+
- FR-10654 - Update nvmrc load and fix deprecated set-output
|
|
10
|
+
- FR-10654 - Fix build script
|
|
11
|
+
- FR-10654 - Add update-sdk-version script and fix prettier command
|
|
12
|
+
|
|
3
13
|
## [6.7.20](https://github.com/frontegg/frontegg-nextjs/compare/v6.7.19...v6.7.20) (2023-3-16)
|
|
4
14
|
|
|
5
15
|
- Fixed use permission regex issue to accept a wild card
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ and integrate them into their SaaS portals in up to 5 lines of code.
|
|
|
10
10
|
- [Add to existing project](#add-to-existing-project)
|
|
11
11
|
- [Using Vercel platform with custom domain](#using-vercel-platform-with-custom-domain)
|
|
12
12
|
- [Getting Started](#getting-started)
|
|
13
|
-
- [Create Frontegg
|
|
13
|
+
- [Create Frontegg workspace](#create-frontegg-workspace)
|
|
14
14
|
- [Setup environment](#setup-environment)
|
|
15
15
|
- [Documentation](#documentation)
|
|
16
16
|
- [API Reference](#api-reference)
|
|
@@ -22,27 +22,9 @@ and integrate them into their SaaS portals in up to 5 lines of code.
|
|
|
22
22
|
|
|
23
23
|
## Installation
|
|
24
24
|
|
|
25
|
-
###
|
|
25
|
+
### Add Frontegg to Next.JS project
|
|
26
26
|
|
|
27
|
-
To
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npx create-next-app --example "https://github.com/frontegg/frontegg-nextjs" --example-path "apps/example" my-nextjs-app-name
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
or
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
yarn create next-app --example "https://github.com/frontegg/frontegg-nextjs" --example-path "apps/example" my-nextjs-app-name
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
> If you've previously installed `create-react-app` globally via `npm install -g create-next-app`, we recommend you uninstall the package using `npm uninstall -g create-next-app` or `yarn global remove create-next-app` to ensure that `npx` always uses the latest version.
|
|
40
|
-
>
|
|
41
|
-
> Global installations of `create-next-app` are no longer supported.
|
|
42
|
-
|
|
43
|
-
### Add to existing project
|
|
44
|
-
|
|
45
|
-
To Add Frontegg to your existing Nextjs project, follow below steps:
|
|
27
|
+
To Add Frontegg to your existing Next.JS project, follow below steps:
|
|
46
28
|
|
|
47
29
|
1. Use package manager to install Frontegg Next.JS library.
|
|
48
30
|
|
|
@@ -61,15 +43,15 @@ To Add Frontegg to your existing Nextjs project, follow below steps:
|
|
|
61
43
|
```tsx
|
|
62
44
|
// ./pages/_app.tsx
|
|
63
45
|
|
|
64
|
-
import { withFronteggApp } from
|
|
46
|
+
import { withFronteggApp } from "@frontegg/nextjs";
|
|
65
47
|
|
|
66
48
|
function CustomApp({ Component, pageProps }: AppProps) {
|
|
67
49
|
return <Component {...pageProps} />;
|
|
68
50
|
}
|
|
69
51
|
|
|
70
|
-
|
|
52
|
+
export default withFronteggApp(CustomApp, {
|
|
71
53
|
hostedLoginBox: true
|
|
72
|
-
|
|
54
|
+
});
|
|
73
55
|
```
|
|
74
56
|
|
|
75
57
|
3. Create files for frontegg middleware under `./pages/api/frontegg/[...frontegg-middleware].ts`:
|
|
@@ -93,16 +75,16 @@ To Add Frontegg to your existing Nextjs project, follow below steps:
|
|
|
93
75
|
|
|
94
76
|
### Using Vercel platform with custom domain
|
|
95
77
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
78
|
+
1. Visit `https://vercel.com/[ACCOUNT_ID]/[PROJECT_ID]/settings/environment-variables`
|
|
79
|
+
2. Add `FRONTEGG_APP_URL` environment variable for each Vercel Environment
|
|
80
|
+

|
|
81
|
+
|
|
100
82
|
|
|
101
83
|
## Getting Started
|
|
102
84
|
|
|
103
|
-
### Create Frontegg
|
|
85
|
+
### Create Frontegg workspace
|
|
104
86
|
|
|
105
|
-
Navigate to [Frontegg Portal
|
|
87
|
+
Navigate to [Frontegg Portal Settings](https://portal.frontegg.com/development/settings), If you don't have application
|
|
106
88
|
follow integration steps after signing up.
|
|
107
89
|
|
|
108
90
|
Next, configure the "Allowed Origins" in your application under "Domain" tab of the "Settings" page :
|
|
@@ -114,7 +96,7 @@ Copy ClientID, Frontegg Domain from "Settings" page, You'll need these values in
|
|
|
114
96
|
|
|
115
97
|
### Setup environment
|
|
116
98
|
|
|
117
|
-
To
|
|
99
|
+
To set up your Next.js application to communicate with Frontegg, you have to create a new file named `.env.local` under
|
|
118
100
|
your root project directory, this file will be used to store environment variables that will be used, configuration
|
|
119
101
|
options:
|
|
120
102
|
|
|
@@ -230,7 +212,7 @@ export const getServerSideProps: GetServerSideProps = withSSRSession(
|
|
|
230
212
|
|
|
231
213
|
## Next.js 13
|
|
232
214
|
### wrapping your application
|
|
233
|
-
```
|
|
215
|
+
```tsx
|
|
234
216
|
// ./app/layout.tsx
|
|
235
217
|
import { FronteggAppProvider } from '@frontegg/nextjs/server';
|
|
236
218
|
|
|
@@ -247,14 +229,14 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
247
229
|
```
|
|
248
230
|
|
|
249
231
|
### routing
|
|
250
|
-
```
|
|
232
|
+
```tsx
|
|
251
233
|
// ./app/[...frontegg-router]/page.tsx
|
|
252
234
|
export { FronteggAppRouter as default } from '@frontegg/nextjs/client';
|
|
253
235
|
```
|
|
254
236
|
|
|
255
237
|
### server component
|
|
256
|
-
notice that this session is not part of the state and therefore
|
|
257
|
-
```
|
|
238
|
+
notice that this session is not part of the state and therefore won't trigger ui changes when it changes
|
|
239
|
+
```tsx
|
|
258
240
|
// ./app/ServerComponent.tsx
|
|
259
241
|
import { getSession } from "@frontegg/nextjs/server";
|
|
260
242
|
|
|
@@ -267,7 +249,7 @@ export const ServerComponent = async () => {
|
|
|
267
249
|
```
|
|
268
250
|
|
|
269
251
|
### client component
|
|
270
|
-
```
|
|
252
|
+
```tsx
|
|
271
253
|
// ./app/ClientComponent.tsx
|
|
272
254
|
"use client";
|
|
273
255
|
import { useAuth, useLoginWithRedirect } from "@frontegg/nextjs";
|
|
@@ -311,7 +293,7 @@ export const ClientComponent = ({ baseUrl }: { baseUrl?: string }) => {
|
|
|
311
293
|
```
|
|
312
294
|
|
|
313
295
|
### Page
|
|
314
|
-
```
|
|
296
|
+
```tsx
|
|
315
297
|
// ./app/page.tsx
|
|
316
298
|
import { ClientComponent } from "./client";
|
|
317
299
|
import { ServerComponent } from "./server";
|
package/api/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ILoginResponse, ITenantsResponse } from '@frontegg/rest-api';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param headers
|
|
5
|
+
*/
|
|
6
|
+
export declare const getUsers: (headers: Record<string, string>) => Promise<ILoginResponse | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param headers
|
|
10
|
+
*/
|
|
11
|
+
export declare const getTenants: (headers: Record<string, string>) => Promise<ITenantsResponse[] | undefined>;
|
|
12
|
+
declare const _default: {
|
|
13
|
+
loadPublicKey: () => Promise<any>;
|
|
14
|
+
refreshTokenEmbedded: (headers: Record<string, string>) => Promise<Response>;
|
|
15
|
+
refreshTokenHostedLogin: (headers: Record<string, string>, refresh_token: string) => Promise<Response>;
|
|
16
|
+
getUsers: (headers: Record<string, string>) => Promise<ILoginResponse | undefined>;
|
|
17
|
+
getTenants: (headers: Record<string, string>) => Promise<ITenantsResponse[] | undefined>;
|
|
18
|
+
};
|
|
19
|
+
export default _default;
|
package/api/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import config from '../config';
|
|
2
|
+
import { ApiUrls } from './urls';
|
|
3
|
+
import { buildRequestHeaders, Get, parseHttpResponse, Post } from './utils';
|
|
4
|
+
import { fronteggTenantsUrl, fronteggUsersUrl } from '@frontegg/rest-api';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Send HTTP GET to frontegg domain public route to download the JWT public key
|
|
8
|
+
*/
|
|
9
|
+
const loadPublicKey = async () => {
|
|
10
|
+
const response = await fetch(`${config.baseUrl}${ApiUrls.WellKnown.jwks}`, {
|
|
11
|
+
cache: 'force-cache'
|
|
12
|
+
});
|
|
13
|
+
const data = await response.json();
|
|
14
|
+
return data.keys[0];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Send HTTP post request for Frontegg services to refresh token
|
|
19
|
+
* by providing client's fe_ cookies
|
|
20
|
+
*/
|
|
21
|
+
const refreshTokenEmbedded = async headers => {
|
|
22
|
+
return Post({
|
|
23
|
+
url: `${config.baseUrl}${ApiUrls.refreshToken.embedded}`,
|
|
24
|
+
body: '{}',
|
|
25
|
+
credentials: 'include',
|
|
26
|
+
headers: buildRequestHeaders(headers)
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Send HTTP post request for Frontegg services to refresh `hosted login` token
|
|
32
|
+
* by providing client's fe_ as body with grant_type.
|
|
33
|
+
*/
|
|
34
|
+
const refreshTokenHostedLogin = async (headers, refresh_token) => {
|
|
35
|
+
return Post({
|
|
36
|
+
url: `${config.baseUrl}${ApiUrls.refreshToken.hosted}`,
|
|
37
|
+
body: JSON.stringify({
|
|
38
|
+
grant_type: 'refresh_token',
|
|
39
|
+
refresh_token
|
|
40
|
+
}),
|
|
41
|
+
headers: buildRequestHeaders(headers, {
|
|
42
|
+
cookie: headers['cookie']
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param headers
|
|
50
|
+
*/
|
|
51
|
+
export const getUsers = async headers => {
|
|
52
|
+
const headersToSend = buildRequestHeaders(headers);
|
|
53
|
+
const res = await Get({
|
|
54
|
+
url: `${config.baseUrl}/frontegg${fronteggUsersUrl}`,
|
|
55
|
+
headers: headersToSend
|
|
56
|
+
});
|
|
57
|
+
return parseHttpResponse(res);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* @param headers
|
|
63
|
+
*/
|
|
64
|
+
export const getTenants = async headers => {
|
|
65
|
+
const res = await Get({
|
|
66
|
+
url: `${config.baseUrl}/frontegg${fronteggTenantsUrl}`,
|
|
67
|
+
headers: buildRequestHeaders(headers)
|
|
68
|
+
});
|
|
69
|
+
return parseHttpResponse(res);
|
|
70
|
+
};
|
|
71
|
+
export default {
|
|
72
|
+
loadPublicKey,
|
|
73
|
+
refreshTokenEmbedded,
|
|
74
|
+
refreshTokenHostedLogin,
|
|
75
|
+
getUsers,
|
|
76
|
+
getTenants
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
package/api/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["config","ApiUrls","buildRequestHeaders","Get","parseHttpResponse","Post","fronteggTenantsUrl","fronteggUsersUrl","loadPublicKey","response","fetch","baseUrl","WellKnown","jwks","cache","data","json","keys","refreshTokenEmbedded","headers","url","refreshToken","embedded","body","credentials","refreshTokenHostedLogin","refresh_token","hosted","JSON","stringify","grant_type","cookie","getUsers","headersToSend","res","getTenants"],"sources":["../../../../packages/nextjs/src/api/index.ts"],"sourcesContent":["import config from '../config';\nimport { ApiUrls } from './urls';\nimport { buildRequestHeaders, Get, parseHttpResponse, Post } from './utils';\nimport { fronteggTenantsUrl, fronteggUsersUrl, ILoginResponse, ITenantsResponse } from '@frontegg/rest-api';\n\n/**\n * Send HTTP GET to frontegg domain public route to download the JWT public key\n */\nconst loadPublicKey = async () => {\n const response = await fetch(`${config.baseUrl}${ApiUrls.WellKnown.jwks}`, {\n cache: 'force-cache',\n });\n const data = await response.json();\n return data.keys[0];\n};\n\n/**\n * Send HTTP post request for Frontegg services to refresh token\n * by providing client's fe_ cookies\n */\nconst refreshTokenEmbedded = async (headers: Record<string, string>) => {\n return Post({\n url: `${config.baseUrl}${ApiUrls.refreshToken.embedded}`,\n body: '{}',\n credentials: 'include',\n headers: buildRequestHeaders(headers),\n });\n};\n\n/**\n * Send HTTP post request for Frontegg services to refresh `hosted login` token\n * by providing client's fe_ as body with grant_type.\n */\nconst refreshTokenHostedLogin = async (headers: Record<string, string>, refresh_token: string) => {\n return Post({\n url: `${config.baseUrl}${ApiUrls.refreshToken.hosted}`,\n body: JSON.stringify({\n grant_type: 'refresh_token',\n refresh_token,\n }),\n headers: buildRequestHeaders(headers, { cookie: headers['cookie'] }),\n });\n};\n\n/**\n *\n * @param headers\n */\nexport const getUsers = async (headers: Record<string, string>): Promise<ILoginResponse | undefined> => {\n const headersToSend = buildRequestHeaders(headers);\n const res = await Get({\n url: `${config.baseUrl}/frontegg${fronteggUsersUrl}`,\n headers: headersToSend,\n });\n return parseHttpResponse(res);\n};\n\n/**\n *\n * @param headers\n */\nexport const getTenants = async (headers: Record<string, string>): Promise<ITenantsResponse[] | undefined> => {\n const res = await Get({\n url: `${config.baseUrl}/frontegg${fronteggTenantsUrl}`,\n headers: buildRequestHeaders(headers),\n });\n return parseHttpResponse(res);\n};\n\nexport default {\n loadPublicKey,\n refreshTokenEmbedded,\n refreshTokenHostedLogin,\n getUsers,\n getTenants,\n};\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,WAAW;AAC9B,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAASC,mBAAmB,EAAEC,GAAG,EAAEC,iBAAiB,EAAEC,IAAI,QAAQ,SAAS;AAC3E,SAASC,kBAAkB,EAAEC,gBAAgB,QAA0C,oBAAoB;;AAE3G;AACA;AACA;AACA,MAAMC,aAAa,GAAG,YAAY;EAChC,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAAE,GAAEV,MAAM,CAACW,OAAQ,GAAEV,OAAO,CAACW,SAAS,CAACC,IAAK,EAAC,EAAE;IACzEC,KAAK,EAAE;EACT,CAAC,CAAC;EACF,MAAMC,IAAI,GAAG,MAAMN,QAAQ,CAACO,IAAI,EAAE;EAClC,OAAOD,IAAI,CAACE,IAAI,CAAC,CAAC,CAAC;AACrB,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,GAAG,MAAOC,OAA+B,IAAK;EACtE,OAAOd,IAAI,CAAC;IACVe,GAAG,EAAG,GAAEpB,MAAM,CAACW,OAAQ,GAAEV,OAAO,CAACoB,YAAY,CAACC,QAAS,EAAC;IACxDC,IAAI,EAAE,IAAI;IACVC,WAAW,EAAE,SAAS;IACtBL,OAAO,EAAEjB,mBAAmB,CAACiB,OAAO;EACtC,CAAC,CAAC;AACJ,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMM,uBAAuB,GAAG,OAAON,OAA+B,EAAEO,aAAqB,KAAK;EAChG,OAAOrB,IAAI,CAAC;IACVe,GAAG,EAAG,GAAEpB,MAAM,CAACW,OAAQ,GAAEV,OAAO,CAACoB,YAAY,CAACM,MAAO,EAAC;IACtDJ,IAAI,EAAEK,IAAI,CAACC,SAAS,CAAC;MACnBC,UAAU,EAAE,eAAe;MAC3BJ;IACF,CAAC,CAAC;IACFP,OAAO,EAAEjB,mBAAmB,CAACiB,OAAO,EAAE;MAAEY,MAAM,EAAEZ,OAAO,CAAC,QAAQ;IAAE,CAAC;EACrE,CAAC,CAAC;AACJ,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAMa,QAAQ,GAAG,MAAOb,OAA+B,IAA0C;EACtG,MAAMc,aAAa,GAAG/B,mBAAmB,CAACiB,OAAO,CAAC;EAClD,MAAMe,GAAG,GAAG,MAAM/B,GAAG,CAAC;IACpBiB,GAAG,EAAG,GAAEpB,MAAM,CAACW,OAAQ,YAAWJ,gBAAiB,EAAC;IACpDY,OAAO,EAAEc;EACX,CAAC,CAAC;EACF,OAAO7B,iBAAiB,CAAC8B,GAAG,CAAC;AAC/B,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAG,MAAOhB,OAA+B,IAA8C;EAC5G,MAAMe,GAAG,GAAG,MAAM/B,GAAG,CAAC;IACpBiB,GAAG,EAAG,GAAEpB,MAAM,CAACW,OAAQ,YAAWL,kBAAmB,EAAC;IACtDa,OAAO,EAAEjB,mBAAmB,CAACiB,OAAO;EACtC,CAAC,CAAC;EACF,OAAOf,iBAAiB,CAAC8B,GAAG,CAAC;AAC/B,CAAC;AAED,eAAe;EACb1B,aAAa;EACbU,oBAAoB;EACpBO,uBAAuB;EACvBO,QAAQ;EACRG;AACF,CAAC"}
|
package/api/package.json
ADDED
package/api/urls.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const ApiUrls: {
|
|
2
|
+
WellKnown: {
|
|
3
|
+
jwks: string;
|
|
4
|
+
};
|
|
5
|
+
refreshToken: {
|
|
6
|
+
embedded: string;
|
|
7
|
+
hosted: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
interface BuildRouteResult {
|
|
11
|
+
asPath: string;
|
|
12
|
+
asUrl: URL;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builds a login route with a redirect URL encoded as a query parameter.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} redirectUrl - The URL to redirect to after successful login.
|
|
18
|
+
* @returns {BuildRouteResult} An object containing the generated login route and URL.
|
|
19
|
+
*
|
|
20
|
+
* @throws {TypeError} If redirectUrl is not a string.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildLoginRoute(redirectUrl: string): BuildRouteResult;
|
|
23
|
+
/**
|
|
24
|
+
* Builds a HostedLogin's logout route with a redirect URL encoded as a query parameter.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} redirectUrl - The URL to redirect to after successful login.
|
|
27
|
+
* @param {string} baseUrl - The frontegg domain url
|
|
28
|
+
* @returns {BuildRouteResult} An object containing the generated login route and URL.
|
|
29
|
+
*
|
|
30
|
+
* @throws {TypeError} If redirectUrl is not a string.
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildLogoutRoute(redirectUrl: string, baseUrl: string): BuildRouteResult;
|
|
33
|
+
export {};
|
package/api/urls.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { fronteggRefreshTokenUrl } from '@frontegg/rest-api';
|
|
2
|
+
import config from '../config';
|
|
3
|
+
export const ApiUrls = {
|
|
4
|
+
WellKnown: {
|
|
5
|
+
jwks: `/.well-known/jwks.json`
|
|
6
|
+
},
|
|
7
|
+
refreshToken: {
|
|
8
|
+
embedded: `/frontegg${fronteggRefreshTokenUrl}`,
|
|
9
|
+
hosted: `/frontegg/oauth/token`
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Builds a login route with a redirect URL encoded as a query parameter.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} redirectUrl - The URL to redirect to after successful login.
|
|
16
|
+
* @returns {BuildRouteResult} An object containing the generated login route and URL.
|
|
17
|
+
*
|
|
18
|
+
* @throws {TypeError} If redirectUrl is not a string.
|
|
19
|
+
*/
|
|
20
|
+
export function buildLoginRoute(redirectUrl) {
|
|
21
|
+
const asPath = `${config.appUrl}/account/login?redirectUrl=${encodeURIComponent(redirectUrl)}`;
|
|
22
|
+
const asUrl = new URL(asPath);
|
|
23
|
+
return {
|
|
24
|
+
asPath,
|
|
25
|
+
asUrl
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Builds a HostedLogin's logout route with a redirect URL encoded as a query parameter.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} redirectUrl - The URL to redirect to after successful login.
|
|
33
|
+
* @param {string} baseUrl - The frontegg domain url
|
|
34
|
+
* @returns {BuildRouteResult} An object containing the generated login route and URL.
|
|
35
|
+
*
|
|
36
|
+
* @throws {TypeError} If redirectUrl is not a string.
|
|
37
|
+
*/
|
|
38
|
+
export function buildLogoutRoute(redirectUrl, baseUrl) {
|
|
39
|
+
const asPath = `${baseUrl}/oauth/logout?post_logout_redirect_uri=${encodeURIComponent(redirectUrl)}`;
|
|
40
|
+
const asUrl = new URL(asPath, baseUrl);
|
|
41
|
+
return {
|
|
42
|
+
asPath,
|
|
43
|
+
asUrl
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=urls.js.map
|
package/api/urls.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urls.js","names":["fronteggRefreshTokenUrl","config","ApiUrls","WellKnown","jwks","refreshToken","embedded","hosted","buildLoginRoute","redirectUrl","asPath","appUrl","encodeURIComponent","asUrl","URL","buildLogoutRoute","baseUrl"],"sources":["../../../../packages/nextjs/src/api/urls.ts"],"sourcesContent":["import { fronteggAuthApiRoutes, fronteggRefreshTokenUrl } from '@frontegg/rest-api';\nimport config from '../config';\n\nexport const ApiUrls = {\n WellKnown: {\n jwks: `/.well-known/jwks.json`,\n },\n refreshToken: {\n embedded: `/frontegg${fronteggRefreshTokenUrl}`,\n hosted: `/frontegg/oauth/token`,\n },\n};\n\ninterface BuildRouteResult {\n asPath: string;\n asUrl: URL;\n}\n\n/**\n * Builds a login route with a redirect URL encoded as a query parameter.\n *\n * @param {string} redirectUrl - The URL to redirect to after successful login.\n * @returns {BuildRouteResult} An object containing the generated login route and URL.\n *\n * @throws {TypeError} If redirectUrl is not a string.\n */\nexport function buildLoginRoute(redirectUrl: string): BuildRouteResult {\n const asPath = `${config.appUrl}/account/login?redirectUrl=${encodeURIComponent(redirectUrl)}`;\n const asUrl = new URL(asPath);\n return {\n asPath,\n asUrl,\n };\n}\n\n/**\n * Builds a HostedLogin's logout route with a redirect URL encoded as a query parameter.\n *\n * @param {string} redirectUrl - The URL to redirect to after successful login.\n * @param {string} baseUrl - The frontegg domain url\n * @returns {BuildRouteResult} An object containing the generated login route and URL.\n *\n * @throws {TypeError} If redirectUrl is not a string.\n */\nexport function buildLogoutRoute(redirectUrl: string, baseUrl: string): BuildRouteResult {\n const asPath = `${baseUrl}/oauth/logout?post_logout_redirect_uri=${encodeURIComponent(redirectUrl)}`;\n const asUrl = new URL(asPath, baseUrl);\n return {\n asPath,\n asUrl,\n };\n}\n"],"mappings":"AAAA,SAAgCA,uBAAuB,QAAQ,oBAAoB;AACnF,OAAOC,MAAM,MAAM,WAAW;AAE9B,OAAO,MAAMC,OAAO,GAAG;EACrBC,SAAS,EAAE;IACTC,IAAI,EAAG;EACT,CAAC;EACDC,YAAY,EAAE;IACZC,QAAQ,EAAG,YAAWN,uBAAwB,EAAC;IAC/CO,MAAM,EAAG;EACX;AACF,CAAC;AAOD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAe,CAACC,WAAmB,EAAoB;EACrE,MAAMC,MAAM,GAAI,GAAET,MAAM,CAACU,MAAO,8BAA6BC,kBAAkB,CAACH,WAAW,CAAE,EAAC;EAC9F,MAAMI,KAAK,GAAG,IAAIC,GAAG,CAACJ,MAAM,CAAC;EAC7B,OAAO;IACLA,MAAM;IACNG;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,gBAAgB,CAACN,WAAmB,EAAEO,OAAe,EAAoB;EACvF,MAAMN,MAAM,GAAI,GAAEM,OAAQ,0CAAyCJ,kBAAkB,CAACH,WAAW,CAAE,EAAC;EACpG,MAAMI,KAAK,GAAG,IAAIC,GAAG,CAACJ,MAAM,EAAEM,OAAO,CAAC;EACtC,OAAO;IACLN,MAAM;IACNG;EACF,CAAC;AACH"}
|
package/api/utils.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
interface GetRequestOptions {
|
|
2
|
+
url: string;
|
|
3
|
+
credentials?: RequestCredentials;
|
|
4
|
+
headers?: HeadersInit;
|
|
5
|
+
}
|
|
6
|
+
export declare const Get: ({ url, credentials, headers }: GetRequestOptions) => Promise<Response>;
|
|
7
|
+
interface PostRequestOptions extends GetRequestOptions {
|
|
8
|
+
body: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const Post: ({ url, credentials, headers, body }: PostRequestOptions) => Promise<Response>;
|
|
11
|
+
/**
|
|
12
|
+
* NodeJS 18 start using undici as http request handler,
|
|
13
|
+
* undici http request does not accept invalid headers
|
|
14
|
+
* for more details see:
|
|
15
|
+
* https://github.com/nodejs/undici/blob/2b260c997ad4efe4ed2064b264b4b546a59e7a67/lib/core/request.js#L282
|
|
16
|
+
* @param headers
|
|
17
|
+
*/
|
|
18
|
+
export declare function removeInvalidHeaders(headers: Record<string, string>): {
|
|
19
|
+
[x: string]: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Build fetch request headers, remove invalid http headers
|
|
23
|
+
* @param headers - Incoming request headers
|
|
24
|
+
* @param additionalHeaders - Specify additional headers
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildRequestHeaders(headers: Record<string, any>, additionalHeaders?: Record<string, string>): Record<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Return parsed json response if http status code = 200
|
|
29
|
+
* @param res
|
|
30
|
+
*/
|
|
31
|
+
export declare const parseHttpResponse: <T>(res: Response) => Promise<T | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Checks if the given path is a frontegg authentication API route, ends with '/postlogin', or ends with '/prelogin'.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} path - The path to check for authentication API routes.
|
|
36
|
+
* @returns {boolean} Returns true if the path is a frontegg authentication API route or ends with '/postlogin' or '/prelogin'; otherwise, returns false.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isAuthPath(path: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if the given path matches the pattern for a social login prelogin route.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} path - The path to check for a social login prelogin route pattern.
|
|
43
|
+
* @returns {boolean} Returns true if the path matches the social login prelogin route pattern; otherwise, returns false.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isSocialLoginPath(path: string): boolean;
|
|
46
|
+
export {};
|
package/api/utils.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import config from '../config';
|
|
3
|
+
import sdkVersion from '../sdkVersion';
|
|
4
|
+
import nextjsPkg from 'next/package.json';
|
|
5
|
+
import { fronteggAuthApiRoutes } from '@frontegg/rest-api';
|
|
6
|
+
import { headerCharRegex } from '../utils/common/constants';
|
|
7
|
+
export const Get = ({
|
|
8
|
+
url,
|
|
9
|
+
credentials = 'include',
|
|
10
|
+
headers
|
|
11
|
+
}) => fetch(url, {
|
|
12
|
+
method: 'GET',
|
|
13
|
+
credentials,
|
|
14
|
+
headers
|
|
15
|
+
});
|
|
16
|
+
export const Post = ({
|
|
17
|
+
url,
|
|
18
|
+
credentials = 'include',
|
|
19
|
+
headers,
|
|
20
|
+
body
|
|
21
|
+
}) => fetch(url, {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
credentials,
|
|
24
|
+
headers,
|
|
25
|
+
body
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* NodeJS 18 start using undici as http request handler,
|
|
30
|
+
* undici http request does not accept invalid headers
|
|
31
|
+
* for more details see:
|
|
32
|
+
* https://github.com/nodejs/undici/blob/2b260c997ad4efe4ed2064b264b4b546a59e7a67/lib/core/request.js#L282
|
|
33
|
+
* @param headers
|
|
34
|
+
*/
|
|
35
|
+
export function removeInvalidHeaders(headers) {
|
|
36
|
+
const newHeaders = _extends({}, headers);
|
|
37
|
+
Object.keys(newHeaders).forEach(key => {
|
|
38
|
+
const val = headers[key];
|
|
39
|
+
if (val && typeof val === 'object' && !Array.isArray(val)) {
|
|
40
|
+
delete newHeaders[key];
|
|
41
|
+
} else if (headerCharRegex.exec(val) !== null) {
|
|
42
|
+
delete newHeaders[key];
|
|
43
|
+
} else if (val === undefined || val === null) {
|
|
44
|
+
delete newHeaders[key];
|
|
45
|
+
} else if (key.length === 10 && key === 'connection') {
|
|
46
|
+
delete newHeaders[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return newHeaders;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Build fetch request headers, remove invalid http headers
|
|
54
|
+
* @param headers - Incoming request headers
|
|
55
|
+
* @param additionalHeaders - Specify additional headers
|
|
56
|
+
*/
|
|
57
|
+
export function buildRequestHeaders(headers, additionalHeaders = {}) {
|
|
58
|
+
let cookie = headers['cookie'];
|
|
59
|
+
if (cookie != null && typeof cookie === 'string') {
|
|
60
|
+
cookie = cookie.replace(/fe_session-[^=]*=[^;]*$/, '').replace(/fe_session-[^=]*=[^;]*;/, '');
|
|
61
|
+
}
|
|
62
|
+
const preparedHeaders = {
|
|
63
|
+
authorization: headers['authorization'],
|
|
64
|
+
'accept-encoding': headers['accept-encoding'],
|
|
65
|
+
'accept-language': headers['accept-language'],
|
|
66
|
+
accept: headers['accept'],
|
|
67
|
+
'content-type': 'application/json',
|
|
68
|
+
origin: config.baseUrl,
|
|
69
|
+
cookie,
|
|
70
|
+
'user-agent': headers['user-agent'],
|
|
71
|
+
'cache-control': headers['cache-control'],
|
|
72
|
+
'x-frontegg-framework': `next@${nextjsPkg.version}`,
|
|
73
|
+
'x-frontegg-sdk': `@frontegg/nextjs@${sdkVersion.version}`
|
|
74
|
+
};
|
|
75
|
+
return removeInvalidHeaders(_extends({}, preparedHeaders, additionalHeaders));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Return parsed json response if http status code = 200
|
|
80
|
+
* @param res
|
|
81
|
+
*/
|
|
82
|
+
export const parseHttpResponse = async res => {
|
|
83
|
+
if (!res.ok) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
return await res.json();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Checks if the given path is a frontegg authentication API route, ends with '/postlogin', or ends with '/prelogin'.
|
|
91
|
+
*
|
|
92
|
+
* @param {string} path - The path to check for authentication API routes.
|
|
93
|
+
* @returns {boolean} Returns true if the path is a frontegg authentication API route or ends with '/postlogin' or '/prelogin'; otherwise, returns false.
|
|
94
|
+
*/
|
|
95
|
+
export function isAuthPath(path) {
|
|
96
|
+
return fronteggAuthApiRoutes.indexOf(path) !== -1 || path.endsWith('/postlogin') || path.endsWith('/prelogin');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Checks if the given path matches the pattern for a social login prelogin route.
|
|
101
|
+
*
|
|
102
|
+
* @param {string} path - The path to check for a social login prelogin route pattern.
|
|
103
|
+
* @returns {boolean} Returns true if the path matches the social login prelogin route pattern; otherwise, returns false.
|
|
104
|
+
*/
|
|
105
|
+
export function isSocialLoginPath(path) {
|
|
106
|
+
return RegExp('^/identity/resources/auth/v[0-9]*/user/sso/default/.*/prelogin$').test(path);
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=utils.js.map
|
package/api/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["config","sdkVersion","nextjsPkg","fronteggAuthApiRoutes","headerCharRegex","Get","url","credentials","headers","fetch","method","Post","body","removeInvalidHeaders","newHeaders","Object","keys","forEach","key","val","Array","isArray","exec","undefined","length","buildRequestHeaders","additionalHeaders","cookie","replace","preparedHeaders","authorization","accept","origin","baseUrl","version","parseHttpResponse","res","ok","json","isAuthPath","path","indexOf","endsWith","isSocialLoginPath","RegExp","test"],"sources":["../../../../packages/nextjs/src/api/utils.ts"],"sourcesContent":["import config from '../config';\nimport sdkVersion from '../sdkVersion';\nimport nextjsPkg from 'next/package.json';\nimport { fronteggAuthApiRoutes } from '@frontegg/rest-api';\nimport { headerCharRegex } from '../utils/common/constants';\n\ninterface GetRequestOptions {\n url: string;\n credentials?: RequestCredentials;\n headers?: HeadersInit;\n}\n\nexport const Get = ({ url, credentials = 'include', headers }: GetRequestOptions) =>\n fetch(url, { method: 'GET', credentials, headers });\n\ninterface PostRequestOptions extends GetRequestOptions {\n body: string;\n}\n\nexport const Post = ({ url, credentials = 'include', headers, body }: PostRequestOptions) =>\n fetch(url, { method: 'POST', credentials, headers, body });\n\n/**\n * NodeJS 18 start using undici as http request handler,\n * undici http request does not accept invalid headers\n * for more details see:\n * https://github.com/nodejs/undici/blob/2b260c997ad4efe4ed2064b264b4b546a59e7a67/lib/core/request.js#L282\n * @param headers\n */\nexport function removeInvalidHeaders(headers: Record<string, string>) {\n const newHeaders = { ...headers };\n Object.keys(newHeaders).forEach((key: string) => {\n const val: any = headers[key];\n if (val && typeof val === 'object' && !Array.isArray(val)) {\n delete newHeaders[key];\n } else if (headerCharRegex.exec(val) !== null) {\n delete newHeaders[key];\n } else if (val === undefined || val === null) {\n delete newHeaders[key];\n } else if (key.length === 10 && key === 'connection') {\n delete newHeaders[key];\n }\n });\n return newHeaders;\n}\n\n/**\n * Build fetch request headers, remove invalid http headers\n * @param headers - Incoming request headers\n * @param additionalHeaders - Specify additional headers\n */\nexport function buildRequestHeaders(\n headers: Record<string, any>,\n additionalHeaders: Record<string, string> = {}\n): Record<string, string> {\n let cookie = headers['cookie'];\n if (cookie != null && typeof cookie === 'string') {\n cookie = cookie.replace(/fe_session-[^=]*=[^;]*$/, '').replace(/fe_session-[^=]*=[^;]*;/, '');\n }\n const preparedHeaders: Record<string, string> = {\n authorization: headers['authorization'],\n 'accept-encoding': headers['accept-encoding'],\n 'accept-language': headers['accept-language'],\n accept: headers['accept'],\n 'content-type': 'application/json',\n origin: config.baseUrl,\n cookie,\n 'user-agent': headers['user-agent'],\n 'cache-control': headers['cache-control'],\n 'x-frontegg-framework': `next@${nextjsPkg.version}`,\n 'x-frontegg-sdk': `@frontegg/nextjs@${sdkVersion.version}`,\n };\n\n return removeInvalidHeaders({\n ...preparedHeaders,\n ...additionalHeaders,\n });\n}\n\n/**\n * Return parsed json response if http status code = 200\n * @param res\n */\nexport const parseHttpResponse = async <T>(res: Response): Promise<T | undefined> => {\n if (!res.ok) {\n return undefined;\n }\n return await res.json();\n};\n\n/**\n * Checks if the given path is a frontegg authentication API route, ends with '/postlogin', or ends with '/prelogin'.\n *\n * @param {string} path - The path to check for authentication API routes.\n * @returns {boolean} Returns true if the path is a frontegg authentication API route or ends with '/postlogin' or '/prelogin'; otherwise, returns false.\n */\nexport function isAuthPath(path: string): boolean {\n return fronteggAuthApiRoutes.indexOf(path) !== -1 || path.endsWith('/postlogin') || path.endsWith('/prelogin');\n}\n\n/**\n * Checks if the given path matches the pattern for a social login prelogin route.\n *\n * @param {string} path - The path to check for a social login prelogin route pattern.\n * @returns {boolean} Returns true if the path matches the social login prelogin route pattern; otherwise, returns false.\n */\nexport function isSocialLoginPath(path: string): boolean {\n return RegExp('^/identity/resources/auth/v[0-9]*/user/sso/default/.*/prelogin$').test(path);\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
+
const _excluded = ["children", "basename"];
|
|
6
|
+
import { FronteggBaseProvider } from '../common';
|
|
7
|
+
import { useRouter } from 'next/navigation';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
export const ClientFronteggProvider = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
children,
|
|
13
|
+
basename
|
|
14
|
+
} = _ref,
|
|
15
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
16
|
+
const router = useRouter();
|
|
17
|
+
const basePath = process.env.__NEXT_ROUTER_BASEPATH || '';
|
|
18
|
+
return /*#__PURE__*/_jsx(FronteggBaseProvider, _extends({
|
|
19
|
+
router: router,
|
|
20
|
+
basename: basename != null ? basename : basePath
|
|
21
|
+
}, props, {
|
|
22
|
+
children: children
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=ClientFronteggProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientFronteggProvider.js","names":["FronteggBaseProvider","useRouter","React","ClientFronteggProvider","children","basename","props","router","basePath","process","env","__NEXT_ROUTER_BASEPATH"],"sources":["../../../../packages/nextjs/src/app/ClientFronteggProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FronteggProviderProps } from '../types';\nimport { FronteggBaseProvider } from '../common';\nimport { useRouter } from 'next/navigation';\nimport React, { FC } from 'react';\n\nexport const ClientFronteggProvider: FC<Omit<FronteggProviderProps, 'router'>> = ({ children, basename, ...props }) => {\n const router = useRouter();\n const basePath = process.env.__NEXT_ROUTER_BASEPATH || '';\n\n return (\n <FronteggBaseProvider router={router} basename={basename ?? basePath} {...props}>\n {children}\n </FronteggBaseProvider>\n );\n};\n"],"mappings":"AAAA,YAAY;;AAAC;AAAA;AAAA;AAGb,SAASA,oBAAoB,QAAQ,WAAW;AAChD,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,OAAOC,KAAK,MAAc,OAAO;AAAC;AAElC,OAAO,MAAMC,sBAAiE,GAAG,QAAsC;EAAA,IAArC;MAAEC,QAAQ;MAAEC;IAAmB,CAAC;IAAPC,KAAK;EAC9G,MAAMC,MAAM,GAAGN,SAAS,EAAE;EAC1B,MAAMO,QAAQ,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAsB,IAAI,EAAE;EAEzD,oBACE,KAAC,oBAAoB;IAAC,MAAM,EAAEJ,MAAO;IAAC,QAAQ,EAAEF,QAAQ,WAARA,QAAQ,GAAIG;EAAS,GAAKF,KAAK;IAAA,UAC5EF;EAAQ,GACY;AAE3B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { FronteggAppOptions } from '@frontegg/types';
|
|
3
|
+
export type FronteggAppProviderProps = PropsWithChildren<Omit<FronteggAppOptions, 'contextOptions'>>;
|
|
4
|
+
export declare const FronteggAppProvider: (options: FronteggAppProviderProps) => Promise<JSX.Element>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ClientFronteggProvider } from './ClientFronteggProvider';
|
|
4
|
+
import { getAppHeaders, getAppSession } from './helpers';
|
|
5
|
+
import config from '../config';
|
|
6
|
+
import fetchUserData from '../utils/fetchUserData';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export const FronteggAppProvider = async options => {
|
|
9
|
+
const appEnvConfig = config.appEnvConfig;
|
|
10
|
+
const userData = await fetchUserData({
|
|
11
|
+
getSession: getAppSession,
|
|
12
|
+
getHeaders: getAppHeaders
|
|
13
|
+
});
|
|
14
|
+
const providerProps = _extends({}, appEnvConfig, userData, options);
|
|
15
|
+
return /*#__PURE__*/_jsx(ClientFronteggProvider, _extends({}, providerProps));
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=FronteggAppProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FronteggAppProvider.js","names":["React","ClientFronteggProvider","getAppHeaders","getAppSession","config","fetchUserData","FronteggAppProvider","options","appEnvConfig","userData","getSession","getHeaders","providerProps"],"sources":["../../../../packages/nextjs/src/app/FronteggAppProvider.tsx"],"sourcesContent":["import React, { PropsWithChildren } from 'react';\nimport { ClientFronteggProvider } from './ClientFronteggProvider';\nimport { FronteggAppOptions } from '@frontegg/types';\nimport { getAppHeaders, getAppSession } from './helpers';\nimport config from '../config';\nimport fetchUserData from '../utils/fetchUserData';\n\nexport type FronteggAppProviderProps = PropsWithChildren<Omit<FronteggAppOptions, 'contextOptions'>>;\n\nexport const FronteggAppProvider = async (options: FronteggAppProviderProps) => {\n const appEnvConfig = config.appEnvConfig;\n const userData = await fetchUserData({ getSession: getAppSession, getHeaders: getAppHeaders });\n\n const providerProps = {\n ...appEnvConfig,\n ...userData,\n ...options,\n };\n\n return <ClientFronteggProvider {...providerProps} />;\n};\n"],"mappings":";AAAA,OAAOA,KAAK,MAA6B,OAAO;AAChD,SAASC,sBAAsB,QAAQ,0BAA0B;AAEjE,SAASC,aAAa,EAAEC,aAAa,QAAQ,WAAW;AACxD,OAAOC,MAAM,MAAM,WAAW;AAC9B,OAAOC,aAAa,MAAM,wBAAwB;AAAC;AAInD,OAAO,MAAMC,mBAAmB,GAAG,MAAOC,OAAiC,IAAK;EAC9E,MAAMC,YAAY,GAAGJ,MAAM,CAACI,YAAY;EACxC,MAAMC,QAAQ,GAAG,MAAMJ,aAAa,CAAC;IAAEK,UAAU,EAAEP,aAAa;IAAEQ,UAAU,EAAET;EAAc,CAAC,CAAC;EAE9F,MAAMU,aAAa,gBACdJ,YAAY,EACZC,QAAQ,EACRF,OAAO,CACX;EAED,oBAAO,KAAC,sBAAsB,eAAKK,aAAa,EAAI;AACtD,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
/// <reference types="
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export {};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { ParsedUrlQuery } from 'querystring';
|
|
4
|
+
interface FronteggRouterProps {
|
|
5
|
+
params: ParsedUrlQuery & {
|
|
6
|
+
'frontegg-router'?: string[];
|
|
7
|
+
};
|
|
8
|
+
searchParams?: ParsedUrlQuery;
|
|
9
|
+
}
|
|
10
|
+
export declare function FronteggAppRouter({ params: { 'frontegg-router': pathArr }, searchParams }: FronteggRouterProps): JSX.Element | null;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { notFound } from 'next/navigation';
|
|
2
|
+
import { isAuthRoute } from '../utils/routing';
|
|
3
|
+
import { FronteggRouterBase } from '../common/FronteggRouterBase';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export function FronteggAppRouter({
|
|
7
|
+
params: {
|
|
8
|
+
'frontegg-router': pathArr = []
|
|
9
|
+
},
|
|
10
|
+
searchParams
|
|
11
|
+
}) {
|
|
12
|
+
let pathname = `/${pathArr.join('/')}`;
|
|
13
|
+
if (!pathname || pathname.startsWith('/_next/data')) {
|
|
14
|
+
if (searchParams) {
|
|
15
|
+
const query = searchParams[Object.keys(searchParams)[0]];
|
|
16
|
+
pathname = `/${Array.isArray(query) ? query.join('/') : query}`;
|
|
17
|
+
} else {
|
|
18
|
+
notFound();
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (!isAuthRoute(pathname)) {
|
|
23
|
+
notFound();
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return /*#__PURE__*/_jsx(FronteggRouterBase, {
|
|
27
|
+
pathArr: pathArr,
|
|
28
|
+
queryParams: searchParams
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=FronteggAppRouter.js.map
|