@frontegg/react 5.0.11-alpha.3481451403 → 5.0.11-alpha.3508042497
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 +87 -39
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,70 +1,118 @@
|
|
|
1
|
-
|
|
1
|
+
<br />
|
|
2
|
+
<div align="center">
|
|
3
|
+
<img src="https://fronteggstuff.blob.core.windows.net/frongegg-logos/logo-transparent.png" alt="Frontegg Logo" width="400" height="90">
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<h3 align="center">Frontegg React.js</h3>
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
and integrate them into their SaaS portals in up to 5 lines of code.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
### The new @frontegg/react uses AdminPortal and LoginBox instead of multiple components.
|
|
7
|
+
<p align="center">
|
|
8
|
+
Frontegg is a web platform where SaaS companies can set up their fully managed, scalable and brand aware - SaaS features and integrate them into their SaaS portals in up to 5 lines of code.
|
|
9
|
+
<br />
|
|
10
|
+
</div>
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
14
|
Use the package manager [npm](https://www.npmjs.com/) to install frontegg React.JS library.
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npm install @frontegg/react
|
|
17
|
+
npm install @frontegg/react react-router-dom
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Configuration
|
|
21
21
|
|
|
22
|
-
Wrap your
|
|
22
|
+
Wrap your root component with `Frontegg Provider`:
|
|
23
23
|
|
|
24
24
|
```js
|
|
25
|
-
import
|
|
25
|
+
import React from 'react';
|
|
26
|
+
import ReactDOM from 'react-dom'; // For react 17
|
|
27
|
+
// For react 18: import ReactDOM from 'react-dom/client';
|
|
28
|
+
import App from './App';
|
|
29
|
+
import './index.css';
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
baseUrl: 'https://{HOST}.frontegg.com', // Your backend base URL (frontegg will direct the requests to it)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const App = () => {
|
|
32
|
-
return <FronteggProvider contextOptions={contextOptions}>
|
|
33
|
-
{/*...*/}
|
|
34
|
-
</FronteggProvider>
|
|
35
|
-
}
|
|
31
|
+
import { FronteggProvider } from '@frontegg/react';
|
|
36
32
|
|
|
33
|
+
const contextOptions = {
|
|
34
|
+
baseUrl: 'https://[YOUR_SUBDOMAIN].frontegg.com',
|
|
35
|
+
clientId: '[YOUR-CLIENT-ID]'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// For react 18:
|
|
39
|
+
// const root = ReactDOM.createRoot(document.getElementById('root'));
|
|
40
|
+
// root.render(
|
|
41
|
+
ReactDOM.render(
|
|
42
|
+
<FronteggProvider contextOptions={contextOptions} hostedLoginBox={true}>
|
|
43
|
+
<App />
|
|
44
|
+
</FronteggProvider>,
|
|
45
|
+
document.getElementById('root')
|
|
46
|
+
);
|
|
37
47
|
```
|
|
48
|
+
In order to get your subDomain and clientId, visit our portal.
|
|
38
49
|
|
|
39
|
-
###
|
|
50
|
+
### Redirect to login
|
|
40
51
|
|
|
41
|
-
|
|
52
|
+
Using the Frontegg useAuth hook, you can determine whether a user is authenticated or not.
|
|
53
|
+
If the user is not authenticated, you can redirect the user to login via the useLoginWithRedirect hook as shown below.
|
|
42
54
|
|
|
43
55
|
```js
|
|
44
|
-
import
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
import './App.css';
|
|
57
|
+
// import { useEffect } from 'react';
|
|
58
|
+
import { ContextHolder } from '@frontegg/rest-api';
|
|
59
|
+
import { useAuth, useLoginWithRedirect } from '@frontegg/react';
|
|
60
|
+
|
|
61
|
+
function App() {
|
|
62
|
+
const { user, isAuthenticated } = useAuth();
|
|
63
|
+
const loginWithRedirect = useLoginWithRedirect();
|
|
64
|
+
|
|
65
|
+
// Uncomment this to redirect to login automatically
|
|
66
|
+
// useEffect(() => {
|
|
67
|
+
// if (!isAuthenticated) {
|
|
68
|
+
// loginWithRedirect();
|
|
69
|
+
// }
|
|
70
|
+
// }, [isAuthenticated, loginWithRedirect]);
|
|
71
|
+
|
|
72
|
+
const logout = () => {
|
|
73
|
+
const baseUrl = ContextHolder.getContext().baseUrl;
|
|
74
|
+
window.location.href = `${baseUrl}/oauth/logout?post_logout_redirect_uri=${window.location}`;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<div className='App'>
|
|
79
|
+
{isAuthenticated ? (
|
|
80
|
+
<div>
|
|
81
|
+
<div>
|
|
82
|
+
<img src={user?.profilePictureUrl} alt={user?.name} />
|
|
83
|
+
</div>
|
|
84
|
+
<div>
|
|
85
|
+
<span>Logged in as: {user?.name}</span>
|
|
86
|
+
</div>
|
|
87
|
+
<div>
|
|
88
|
+
<button onClick={() => alert(user.accessToken)}>What is my access token?</button>
|
|
89
|
+
</div>
|
|
90
|
+
<div>
|
|
91
|
+
<button onClick={() => logout()}>Click to logout</button>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
) : (
|
|
95
|
+
<div>
|
|
96
|
+
<button onClick={() => loginWithRedirect()}>Click me to login</button>
|
|
97
|
+
</div>
|
|
98
|
+
)}
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
52
101
|
}
|
|
102
|
+
|
|
103
|
+
export default App;
|
|
53
104
|
```
|
|
54
105
|
|
|
106
|
+
## Integrate Admin Portal
|
|
107
|
+
|
|
55
108
|
Opening the Admin Portal is available via the following code snippet.
|
|
56
109
|
|
|
57
110
|
```js
|
|
58
111
|
import { AdminPortal } from '@frontegg/react'
|
|
59
112
|
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
{/*... your application tabs ...*/}
|
|
113
|
+
const handleClick = () => {
|
|
114
|
+
AdminPortal.show();
|
|
115
|
+
};
|
|
64
116
|
|
|
65
|
-
|
|
66
|
-
Open Admin Portal
|
|
67
|
-
</button>
|
|
68
|
-
</nav>
|
|
69
|
-
}
|
|
117
|
+
<button onClick={handleClick}>Settings</button>
|
|
70
118
|
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/react",
|
|
3
3
|
"libName": "FronteggReact",
|
|
4
|
-
"version": "5.0.11-alpha.
|
|
4
|
+
"version": "5.0.11-alpha.3508042497",
|
|
5
5
|
"author": "Frontegg LTD",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"types": "index.d.ts",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"build:watch": "rm -rf dist && mkdir dist && rollup -w -c ./rollup.config.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@frontegg/js": "6.45.0-alpha.
|
|
14
|
-
"@frontegg/react-hooks": "6.45.0-alpha.
|
|
13
|
+
"@frontegg/js": "6.45.0-alpha.2",
|
|
14
|
+
"@frontegg/react-hooks": "6.45.0-alpha.2"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"react": ">16.9.0",
|