@frontegg/nextjs 3.0.11 → 3.0.13-alpha.1351304234
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/README.md +68 -0
- package/index.d.ts +3 -1
- package/index.js +27 -6
- package/index.js.map +1 -1
- package/package.json +8 -14
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Frontegg Next.js
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Frontegg is a web platform where SaaS companies can set up their fully managed, scalable and brand aware - SaaS features
|
|
6
|
+
and integrate them into their SaaS portals in up to 5 lines of code.
|
|
7
|
+
|
|
8
|
+
### @frontegg/nextjs uses AdminPortal and LoginBox.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Use the package manager [npm](https://www.npmjs.com/) to install frontegg Next.js library.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @frontegg/nextjs
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Configuration
|
|
19
|
+
|
|
20
|
+
Wrap your application in `_app.js` with `Frontegg Provider`:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { FronteggProvider } from '@frontegg/nextjs'
|
|
24
|
+
|
|
25
|
+
const contextOptions = {
|
|
26
|
+
baseUrl: 'https://{HOST}.frontegg.com',// Your backend base URL (frontegg will direct the requests to it)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const App = ({ Component, pageProps }) => {
|
|
30
|
+
return <FronteggProvider contextOptions={contextOptions}>
|
|
31
|
+
<Component {...pageProps}/>
|
|
32
|
+
</FronteggProvider>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Usage
|
|
38
|
+
|
|
39
|
+
You can use React Hooks to access Frontegg store.
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import { useAuthUser } from '@frontegg/nextjs'
|
|
43
|
+
|
|
44
|
+
const HomePage = () => {
|
|
45
|
+
const user = useAuthUser();
|
|
46
|
+
|
|
47
|
+
return <div>
|
|
48
|
+
Logged In user: {user.email}
|
|
49
|
+
</div>
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Openning the Admin Portal is available via the following code snippet.
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import { AdminPortal } from '@frontegg/nextjs'
|
|
57
|
+
|
|
58
|
+
const Toolbar = () => {
|
|
59
|
+
|
|
60
|
+
return <nav>
|
|
61
|
+
{/*... your application tabs ...*/}
|
|
62
|
+
|
|
63
|
+
<button onClick={() => AdminPortal.show()}>
|
|
64
|
+
Open Admin Portal
|
|
65
|
+
</button>
|
|
66
|
+
</nav>
|
|
67
|
+
}
|
|
68
|
+
```
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './FronteggProvider';
|
|
2
2
|
export * from './AuthorizedContent';
|
|
3
3
|
export { AdminPortal } from '@frontegg/admin-portal';
|
|
4
|
-
export * from '@frontegg/react-hooks';
|
|
4
|
+
export * from '@frontegg/react-hooks/auth';
|
|
5
|
+
export * from '@frontegg/react-hooks/audits';
|
|
6
|
+
export * from '@frontegg/react-hooks/connectivity';
|
package/index.js
CHANGED
|
@@ -11,6 +11,9 @@ var adminPortal = require('@frontegg/admin-portal');
|
|
|
11
11
|
var reactHooks = require('@frontegg/react-hooks');
|
|
12
12
|
var restApi = require('@frontegg/rest-api');
|
|
13
13
|
var router = require('next/router');
|
|
14
|
+
var auth = require('@frontegg/react-hooks/auth');
|
|
15
|
+
var audits = require('@frontegg/react-hooks/audits');
|
|
16
|
+
var connectivity = require('@frontegg/react-hooks/connectivity');
|
|
14
17
|
|
|
15
18
|
var Connector = function (_a) {
|
|
16
19
|
var _b;
|
|
@@ -35,6 +38,9 @@ var Connector = function (_a) {
|
|
|
35
38
|
}
|
|
36
39
|
}, []);
|
|
37
40
|
var app = React.useMemo(function () {
|
|
41
|
+
if (typeof window === 'undefined') {
|
|
42
|
+
return { store: null };
|
|
43
|
+
}
|
|
38
44
|
return adminPortal.initialize(tslib.__assign(tslib.__assign({}, props), { contextOptions: tslib.__assign({ requestCredentials: 'include' }, props.contextOptions), onRedirectTo: onRedirectTo }), appName !== null && appName !== void 0 ? appName : 'default');
|
|
39
45
|
}, []);
|
|
40
46
|
restApi.ContextHolder.setOnRedirectTo(onRedirectTo);
|
|
@@ -43,10 +49,9 @@ var Connector = function (_a) {
|
|
|
43
49
|
try {
|
|
44
50
|
(_b = (_a = app.store) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
45
51
|
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
return React__default.createElement(reactHooks.FronteggStoreProvider, tslib.__assign({}, tslib.__assign(tslib.__assign({}, props), { app: app })), props.children);
|
|
52
|
+
catch (e) { }
|
|
53
|
+
}; });
|
|
54
|
+
return React__default.createElement(reactHooks.FronteggStoreProvider, tslib.__assign({}, { app: app }), props.children);
|
|
50
55
|
};
|
|
51
56
|
var FronteggProvider = function (props) {
|
|
52
57
|
var router$1 = router.useRouter();
|
|
@@ -97,11 +102,27 @@ var AuthorizedContent = function (props) {
|
|
|
97
102
|
return isAuthorized ? React__default.createElement(React__default.Fragment, null, props.children) : null;
|
|
98
103
|
};
|
|
99
104
|
|
|
100
|
-
Object.keys(
|
|
105
|
+
Object.keys(auth).forEach(function (k) {
|
|
106
|
+
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function () {
|
|
109
|
+
return auth[k];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
Object.keys(audits).forEach(function (k) {
|
|
114
|
+
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
get: function () {
|
|
117
|
+
return audits[k];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
Object.keys(connectivity).forEach(function (k) {
|
|
101
122
|
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
102
123
|
enumerable: true,
|
|
103
124
|
get: function () {
|
|
104
|
-
return
|
|
125
|
+
return connectivity[k];
|
|
105
126
|
}
|
|
106
127
|
});
|
|
107
128
|
});
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/FronteggProvider.tsx","../src/AuthorizedContent.tsx"],"sourcesContent":["import React, { FC, useCallback, useEffect, useMemo } from 'react';\nimport { initialize } from '@frontegg/admin-portal';\nimport { FronteggAppOptions } from '@frontegg/types';\nimport { FronteggStoreProvider } from '@frontegg/react-hooks';\nimport { ContextHolder, RedirectOptions } from '@frontegg/rest-api';\nimport { NextRouter, useRouter } from 'next/router';\n\ntype ConnectorProps = FronteggAppOptions & {\n router: NextRouter;\n appName?: string;\n};\n\nexport const Connector: FC<ConnectorProps> = ({ router, appName, ...props }) => {\n const isSSR = typeof window === 'undefined';\n\n // v6 or v5\n const baseName = props.basename ?? router.basePath;\n\n const onRedirectTo = useCallback((_path: string, opts?: RedirectOptions) => {\n let path = _path;\n if (path.startsWith(baseName)) {\n path = path.substring(baseName.length);\n }\n if (opts?.preserveQueryParams) {\n path = `${path}${window.location.search}`;\n }\n if (opts?.refresh && !isSSR) {\n // @ts-ignore\n window.Cypress ? router.push(path) : (window.location.href = path);\n } else {\n opts?.replace ? router.replace(path) : router.push(path);\n }\n }, []);\n\n const app = useMemo(() => {\n return initialize(\n {\n ...props,\n contextOptions: {\n requestCredentials: 'include',\n ...props.contextOptions,\n },\n onRedirectTo,\n },\n appName ?? 'default'
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/FronteggProvider.tsx","../src/AuthorizedContent.tsx"],"sourcesContent":["import React, { FC, useCallback, useEffect, useMemo } from 'react';\nimport { initialize } from '@frontegg/admin-portal';\nimport { FronteggAppOptions } from '@frontegg/types';\nimport { FronteggStoreProvider } from '@frontegg/react-hooks';\nimport { ContextHolder, RedirectOptions } from '@frontegg/rest-api';\nimport { NextRouter, useRouter } from 'next/router';\n\ntype ConnectorProps = FronteggAppOptions & {\n router: NextRouter;\n appName?: string;\n};\n\nexport const Connector: FC<ConnectorProps> = ({ router, appName, ...props }) => {\n const isSSR = typeof window === 'undefined';\n\n // v6 or v5\n const baseName = props.basename ?? router.basePath;\n\n const onRedirectTo = useCallback((_path: string, opts?: RedirectOptions) => {\n let path = _path;\n if (path.startsWith(baseName)) {\n path = path.substring(baseName.length);\n }\n if (opts?.preserveQueryParams) {\n path = `${path}${window.location.search}`;\n }\n if (opts?.refresh && !isSSR) {\n // @ts-ignore\n window.Cypress ? router.push(path) : (window.location.href = path);\n } else {\n opts?.replace ? router.replace(path) : router.push(path);\n }\n }, []);\n\n const app = useMemo(() => {\n if (typeof window === 'undefined') {\n return { store: null };\n }\n return initialize(\n {\n ...props,\n contextOptions: {\n requestCredentials: 'include',\n ...props.contextOptions,\n },\n onRedirectTo,\n },\n appName ?? 'default'\n );\n }, []);\n ContextHolder.setOnRedirectTo(onRedirectTo);\n\n useEffect(() => () => {\n try {\n (app.store as any)?.destroy?.();\n } catch (e) {}\n });\n return <FronteggStoreProvider {...({ app } as any)}>{props.children}</FronteggStoreProvider>;\n};\n\nexport const FronteggProvider: FC<FronteggAppOptions> = (props) => {\n const router = useRouter();\n return (\n <Connector {...props} router={router}>\n {props.children}\n </Connector>\n );\n};\n","import React, { FC } from 'react';\nimport { useAuthUserOrNull } from '@frontegg/react-hooks';\n\nexport interface AuthorizationProps {\n requiredRoles?: string[];\n requiredPermissions?: string[];\n render?: (isAuthorized: boolean) => React.ReactNode | null;\n}\n\nexport const AuthorizedContent: FC<AuthorizationProps> = (props) => {\n let isAuthorized = true; // Initially\n const user = useAuthUserOrNull();\n\n if (props.requiredPermissions) {\n if (!user?.permissions || user?.permissions.length === 0) {\n isAuthorized = false;\n }\n\n for (const permission of props.requiredPermissions) {\n if (!user?.permissions?.find(({ key }) => key === permission)) {\n isAuthorized = false;\n }\n }\n }\n\n if (props.requiredRoles) {\n if (!user?.roles || user?.roles.length === 0) {\n isAuthorized = false;\n }\n\n for (const role of props.requiredRoles) {\n if (!user?.roles?.find(({ key }) => key === role)) {\n isAuthorized = false;\n }\n }\n }\n\n if (typeof props.render === 'function') {\n return <>{props.render(isAuthorized)}</>;\n }\n\n return isAuthorized ? <>{props.children}</> : null;\n};\n"],"names":["useCallback","useMemo","initialize","ContextHolder","useEffect","React","FronteggStoreProvider","router","useRouter","useAuthUserOrNull"],"mappings":";;;;;;;;;;;;;;;;;IAYa,SAAS,GAAuB,UAAC,EAA6B;;IAA3B,IAAA,MAAM,YAAA,EAAE,OAAO,aAAA,EAAK,KAAK,oBAA3B,qBAA6B,CAAF;IACvE,IAAM,KAAK,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;;IAG5C,IAAM,QAAQ,SAAG,KAAK,CAAC,QAAQ,mCAAI,MAAM,CAAC,QAAQ,CAAC;IAEnD,IAAM,YAAY,GAAGA,iBAAW,CAAC,UAAC,KAAa,EAAE,IAAsB;QACrE,IAAI,IAAI,GAAG,KAAK,CAAC;QACjB,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC7B,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SACxC;QACD,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,mBAAmB,EAAE;YAC7B,IAAI,GAAG,KAAG,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAQ,CAAC;SAC3C;QACD,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,KAAI,CAAC,KAAK,EAAE;;YAE3B,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI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1C;IAED,OAAO,YAAY,GAAGA,4DAAG,KAAK,CAAC,QAAQ,CAAI,GAAG,IAAI,CAAC;AACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/nextjs",
|
|
3
3
|
"libName": "FronteggNextJs",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.13-alpha.1351304234",
|
|
5
5
|
"author": "Frontegg LTD",
|
|
6
|
-
"main": "index.js",
|
|
7
6
|
"types": "index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "rm -rf dist && mkdir dist && rollup -c ./rollup.config.js",
|
|
10
|
-
"build:watch": "rm -rf dist && mkdir dist && rollup -w -c ./rollup.config.js",
|
|
11
|
-
"test": "jest --runInBand --passWithNoTests -c ../../scripts/jest.config.json --rootDir ."
|
|
12
|
-
},
|
|
13
7
|
"dependencies": {
|
|
14
|
-
"@frontegg/admin-portal": "4.
|
|
15
|
-
"@frontegg/react-hooks": "4.
|
|
16
|
-
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"next": ">10.0.0"
|
|
8
|
+
"@frontegg/admin-portal": "4.29.0",
|
|
9
|
+
"@frontegg/react-hooks": "4.29.0"
|
|
19
10
|
},
|
|
20
11
|
"peerDependencies": {
|
|
21
12
|
"next": ">10.0.0",
|
|
22
13
|
"react": ">16.9.0",
|
|
23
14
|
"react-dom": ">16.9.0"
|
|
24
|
-
}
|
|
25
|
-
|
|
15
|
+
},
|
|
16
|
+
"main": "index.js",
|
|
17
|
+
"module": "index.esm.js",
|
|
18
|
+
"es2015": "index.es.js"
|
|
19
|
+
}
|