@authing/guard-shim-react18 5.0.8-alpha.0 → 5.0.8-alpha.2
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 +2 -136
- package/package.json +9 -13
- package/src/index.tsx +6 -4
- package/README.zh_CN.md +0 -137
- package/scripts/build.js +0 -26
- package/scripts/webpack.esm.config.js +0 -42
- package/scripts/webpack.global.config.js +0 -40
package/README.md
CHANGED
|
@@ -1,137 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
<img width="300" src="https://files.authing.co/authing-console/authing-logo-new-20210924.svg" />
|
|
3
|
-
</div>
|
|
1
|
+
# @authing/guard-shim-react18
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
English | [简体中文](./README.zh_CN.md)
|
|
8
|
-
|
|
9
|
-
<br />
|
|
10
|
-
|
|
11
|
-
Guard is a portable authentication component provided by authing. You can embed it in any application to handle complex user authentication processes in one stop.
|
|
12
|
-
|
|
13
|
-
Prepare your native JavaScript project and follow the guide to connect Guard to your native JavaScript project!
|
|
14
|
-
|
|
15
|
-
## Install
|
|
16
|
-
|
|
17
|
-
From CDN:
|
|
18
|
-
|
|
19
|
-
``` html
|
|
20
|
-
<link rel="stylesheet" href="https://cdn.authing.co/packages/guard/5.0.7/guard.min.css" />
|
|
21
|
-
<script src="https://cdn.authing.co/packages/guard/5.0.7/guard.min.js"></script>
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
From NPM:
|
|
25
|
-
|
|
26
|
-
``` shell
|
|
27
|
-
npm install --save @authing/guard
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Initialize
|
|
31
|
-
|
|
32
|
-
|Key|Type|Default|Requires
|
|
33
|
-
|-----|----|----|----|
|
|
34
|
-
|appId|String| - |Y|
|
|
35
|
-
|mode|normal / modal|normal|N|
|
|
36
|
-
|defaultScene|GuardModuleType|login|N|
|
|
37
|
-
|align|none / left / center / right | none | N | Guard default position|
|
|
38
|
-
|lang|zh-CN / en-US|zh-CN|N|
|
|
39
|
-
|isSSO|Boolean|true|N|
|
|
40
|
-
|host|String| - |N|
|
|
41
|
-
|scope|String| - |N|
|
|
42
|
-
|redirectUri|String| - |N|
|
|
43
|
-
|state|String| - |N|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
``` javascript
|
|
47
|
-
// From CDN
|
|
48
|
-
const guard = new GuardFactory.Guard({
|
|
49
|
-
appId: '62e22721c889dd44bad1dda2',
|
|
50
|
-
host: 'https://guard-test-2022.authing.cn',
|
|
51
|
-
redirectUri: 'http://localhost:3000/callback'
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
// From npm
|
|
55
|
-
const guard = new Guard({
|
|
56
|
-
appId: '62e22721c889dd44bad1dda2',
|
|
57
|
-
host: 'https://guard-test-2022.authing.cn',
|
|
58
|
-
redirectUri: 'http://localhost:3000/callback'
|
|
59
|
-
})
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Guard provides three login modes
|
|
63
|
-
|
|
64
|
-
### Embed mode
|
|
65
|
-
|
|
66
|
-
Render Guard component
|
|
67
|
-
|
|
68
|
-
``` javascript
|
|
69
|
-
guard.start('#root').then(userInfo => {
|
|
70
|
-
console.log(userInfo)
|
|
71
|
-
})
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### modal mode
|
|
75
|
-
|
|
76
|
-
When the parameter 'mode' of Guard instantiation is' modal ', the modal mode is started, and the following API can be used to display and hide the guard.
|
|
77
|
-
|
|
78
|
-
``` javascript
|
|
79
|
-
guard.show()
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
``` javascript
|
|
83
|
-
guard.hide()
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### Redirect mode
|
|
87
|
-
|
|
88
|
-
Login by code, redirect to login page
|
|
89
|
-
|
|
90
|
-
``` javascript
|
|
91
|
-
guard.startWithRedirect()
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Auto handle redirect callback
|
|
95
|
-
|
|
96
|
-
``` javascript
|
|
97
|
-
guard.handleRedirectCallback()
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Logout
|
|
101
|
-
|
|
102
|
-
``` javascript
|
|
103
|
-
guard.logout()
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Regist events
|
|
107
|
-
|
|
108
|
-
``` javascript
|
|
109
|
-
guard.on('load', e => {
|
|
110
|
-
console.log(e)
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
guard.on('login', userInfo => {
|
|
114
|
-
console.log(userInfo)
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
// ......
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
## Integrate authing js sdk instance
|
|
121
|
-
|
|
122
|
-
Guard integrated AuthenticationClient, so you can access all apis of AuthenticationClient, etc:
|
|
123
|
-
|
|
124
|
-
``` javascript
|
|
125
|
-
guard.getAuthClient().then(authClient => {
|
|
126
|
-
authClient.registerByEmail()
|
|
127
|
-
authClient.validateToken()
|
|
128
|
-
// .........
|
|
129
|
-
})
|
|
130
|
-
// ....
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
Refer to [Authentication SDK](https://docs.authing.cn/v2/reference/sdk-for-node/authentication/)
|
|
134
|
-
|
|
135
|
-
## Documentation
|
|
136
|
-
|
|
137
|
-
To check out live examples and docs, visit [docs](https://docs.authing.cn/v2/reference/guard/v3/mpa.html)
|
|
3
|
+
Be only used for internal
|
package/package.json
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authing/guard-shim-react18",
|
|
3
|
-
"version": "5.0.8-alpha.
|
|
3
|
+
"version": "5.0.8-alpha.2",
|
|
4
4
|
"description": "Guard shim for react18",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"autoinstall": "npm ci",
|
|
8
|
-
"build": "echo 'No need to build @authing/guard-shim-react18'",
|
|
8
|
+
"build": "echo 'No need to build for @authing/guard-shim-react18'",
|
|
9
9
|
"lint": "eslint --ext .ts,.tsx src/**",
|
|
10
10
|
"lint:fix": "eslint --fix --ext .ts,.tsx src/**",
|
|
11
11
|
"release:official": "npm publish --verbose --access public",
|
|
12
12
|
"release:alpha": "npm publish --verbose --tag=alpha --access public"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@types/react": "^
|
|
16
|
-
"@types/react-dom": "^
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"webpack": "^5.72.0"
|
|
15
|
+
"@types/react": "^17.0.43",
|
|
16
|
+
"@types/react-dom": "^17.0.14"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": "^18.0.0",
|
|
20
|
+
"react-dom": "^18.0.0"
|
|
22
21
|
},
|
|
23
22
|
"dependencies": {
|
|
24
|
-
"@authing/react18-components": "^4.1.0-alpha.0"
|
|
25
|
-
"axios": "^0.27.2",
|
|
26
|
-
"react": "^18.2.0",
|
|
27
|
-
"react-dom": "^18.2.0"
|
|
23
|
+
"@authing/react18-components": "^4.1.0-alpha.0"
|
|
28
24
|
},
|
|
29
25
|
"author": "https://github.com/authing",
|
|
30
26
|
"license": "MIT",
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
|
|
3
|
-
import { createRoot } from 'react-dom/client'
|
|
3
|
+
import { createRoot, Root } from 'react-dom/client'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
GuardOptions,
|
|
@@ -35,6 +35,8 @@ export class Guard {
|
|
|
35
35
|
|
|
36
36
|
private publicConfig?: Record<string, unknown>
|
|
37
37
|
|
|
38
|
+
private root?: Root
|
|
39
|
+
|
|
38
40
|
constructor(options: GuardOptions) {
|
|
39
41
|
if (!options.appId) {
|
|
40
42
|
throw new Error('appId is required')
|
|
@@ -470,7 +472,7 @@ export class Guard {
|
|
|
470
472
|
return
|
|
471
473
|
}
|
|
472
474
|
|
|
473
|
-
const root = createRoot(target)
|
|
475
|
+
const root = (this.root = createRoot(target))
|
|
474
476
|
|
|
475
477
|
return root.render(
|
|
476
478
|
<ReactAuthingGuard
|
|
@@ -506,8 +508,8 @@ export class Guard {
|
|
|
506
508
|
unmount() {
|
|
507
509
|
const node = Guard.getGuardContainer(this.options.config?.target)
|
|
508
510
|
|
|
509
|
-
if (node) {
|
|
510
|
-
|
|
511
|
+
if (node && this.root) {
|
|
512
|
+
this.root.unmount()
|
|
511
513
|
}
|
|
512
514
|
}
|
|
513
515
|
}
|
package/README.zh_CN.md
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
<div align=center>
|
|
2
|
-
<img width="300" src="https://files.authing.co/authing-console/authing-logo-new-20210924.svg" />
|
|
3
|
-
</div>
|
|
4
|
-
|
|
5
|
-
<br />
|
|
6
|
-
|
|
7
|
-
简体中文 | [English](./README.md)
|
|
8
|
-
|
|
9
|
-
<br />
|
|
10
|
-
|
|
11
|
-
Guard 是 Authing 提供的一种轻便的认证组件,你可以把它嵌入在你任何的 SPA(Single Page Application)应用中,一站式处理复杂的用户认证流程。
|
|
12
|
-
|
|
13
|
-
准备好你的 原生 JavaScript 项目,跟随引导将 Guard 接入到你的 原生 JavaScript 项目中吧!
|
|
14
|
-
|
|
15
|
-
## 安装
|
|
16
|
-
|
|
17
|
-
使用 CDN:
|
|
18
|
-
|
|
19
|
-
``` html
|
|
20
|
-
<link rel="stylesheet" src="https://cdn.authing.co/packages/guard/5.0.0/guard.min.css" />
|
|
21
|
-
<script src="https://cdn.authing.co/packages/guard/5.0.0/guard.min.js"></script>
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
使用 NPM:
|
|
25
|
-
|
|
26
|
-
``` shell
|
|
27
|
-
npm install --save @authing/guard
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## 初始化
|
|
31
|
-
|
|
32
|
-
|字段|类型|默认是|必传
|
|
33
|
-
|-----|----|----|----|
|
|
34
|
-
|appId|String| - |是|
|
|
35
|
-
|mode|normal / modal|normal|否|
|
|
36
|
-
|defaultScene|GuardModuleType|login|否|
|
|
37
|
-
| align |none / left / center / right | none | 否 |
|
|
38
|
-
|lang|zh-CN / en-US|zh-CN|否|
|
|
39
|
-
|isSSO|Boolean|true|否|
|
|
40
|
-
|host|String| - |否|
|
|
41
|
-
|scope|String| - |否|
|
|
42
|
-
|redirectUri|String| - |否|
|
|
43
|
-
|state|String| - |否|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
``` javascript
|
|
47
|
-
// 使用 CDN
|
|
48
|
-
const guard = new GuardFactory.Guard({
|
|
49
|
-
appId: '62e22721c889dd44bad1dda2',
|
|
50
|
-
host: 'https://guard-test-2022.authing.cn',
|
|
51
|
-
redirectUri: 'http://localhost:3000/callback'
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
// 使用 npm
|
|
55
|
-
const guard = new Guard({
|
|
56
|
-
appId: '62e22721c889dd44bad1dda2',
|
|
57
|
-
host: 'https://guard-test-2022.authing.cn',
|
|
58
|
-
redirectUri: 'http://localhost:3000/callback'
|
|
59
|
-
})
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Guard 提供三种登录模式
|
|
63
|
-
|
|
64
|
-
### 嵌入模式
|
|
65
|
-
|
|
66
|
-
渲染 Guard 组件
|
|
67
|
-
|
|
68
|
-
``` javascript
|
|
69
|
-
guard.start('#root').then(userInfo => {
|
|
70
|
-
console.log(userInfo)
|
|
71
|
-
})
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### 弹窗模式
|
|
75
|
-
|
|
76
|
-
当 Guard 实例化的参数 `mode` 为 `modal` 时,将启动模态模式,下面的 API 可用于显示和隐藏 Guard。
|
|
77
|
-
|
|
78
|
-
``` javascript
|
|
79
|
-
guard.show()
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
``` javascript
|
|
83
|
-
guard.hide()
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### 跳转模式
|
|
87
|
-
|
|
88
|
-
使用 code 码登录,跳转到登录页面
|
|
89
|
-
|
|
90
|
-
``` javascript
|
|
91
|
-
guard.startWithRedirect()
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
code 换 token,自动处理页面重定向
|
|
95
|
-
|
|
96
|
-
``` javascript
|
|
97
|
-
guard.handleRedirectCallback()
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
登出
|
|
101
|
-
|
|
102
|
-
``` javascript
|
|
103
|
-
guard.logout()
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## 注册事件
|
|
107
|
-
|
|
108
|
-
``` javascript
|
|
109
|
-
guard.on('load', e => {
|
|
110
|
-
console.log(e)
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
guard.on('login', userInfo => {
|
|
114
|
-
console.log(userInfo)
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
// ......
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
## 集成 Authing JS SDK
|
|
121
|
-
|
|
122
|
-
Guard 集成了 AuthenticationClient,所以你可以访问 AuthenticationClient 的所有 api 等等:
|
|
123
|
-
|
|
124
|
-
``` javascript
|
|
125
|
-
guard.getAuthClient().then(authClient => {
|
|
126
|
-
authClient.registerByEmail()
|
|
127
|
-
authClient.validateToken()
|
|
128
|
-
// .........
|
|
129
|
-
})
|
|
130
|
-
// ....
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
参考 [Authentication SDK](https://docs.authing.cn/v2/reference/sdk-for-node/authentication/)
|
|
134
|
-
|
|
135
|
-
## 文档
|
|
136
|
-
|
|
137
|
-
参考详细文档说明 [docs](https://docs.authing.cn/v2/reference/guard/v3/mpa.html)
|
package/scripts/build.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const rm = require('rimraf')
|
|
3
|
-
const webpack = require('webpack')
|
|
4
|
-
const webpackEsmBundlerConfig = require('./webpack.esm.config')
|
|
5
|
-
const webpackGlobalConfig = require('./webpack.global.config')
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
rm.sync(path.resolve(__dirname, '../', 'dist'))
|
|
9
|
-
} catch (e) {
|
|
10
|
-
console.error('\n\n build guard, failed to delete dist directory, please operate manually \n\n')
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
readyGo()
|
|
14
|
-
|
|
15
|
-
function readyGo () {
|
|
16
|
-
webpack(webpackEsmBundlerConfig, (error) => {
|
|
17
|
-
if (error) {
|
|
18
|
-
console.error('build guard.js esm bundler error: ', error)
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
webpack(webpackGlobalConfig, (error) => {
|
|
22
|
-
if (error) {
|
|
23
|
-
console.error('build guard.js global error: ', error)
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
3
|
-
|
|
4
|
-
function resolve (dir, file = '') {
|
|
5
|
-
return path.resolve(__dirname, '../', dir, file)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
9
|
-
mode: 'production',
|
|
10
|
-
entry: resolve('src/index.tsx'),
|
|
11
|
-
output: {
|
|
12
|
-
filename: 'guard.min.js',
|
|
13
|
-
path: resolve('dist/esm'),
|
|
14
|
-
library: {
|
|
15
|
-
type: 'module'
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
experiments: {
|
|
19
|
-
outputModule: true
|
|
20
|
-
},
|
|
21
|
-
resolve: {
|
|
22
|
-
extensions: ['.ts', '.tsx', '.js']
|
|
23
|
-
},
|
|
24
|
-
module: {
|
|
25
|
-
rules: [
|
|
26
|
-
{
|
|
27
|
-
test: /\.css$/,
|
|
28
|
-
use: [MiniCssExtractPlugin.loader, 'css-loader']
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
test: /\.tsx?$/,
|
|
32
|
-
use: 'ts-loader',
|
|
33
|
-
exclude: /node_modules/
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
},
|
|
37
|
-
plugins: [
|
|
38
|
-
new MiniCssExtractPlugin({
|
|
39
|
-
filename: 'guard.min.css'
|
|
40
|
-
})
|
|
41
|
-
]
|
|
42
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
3
|
-
|
|
4
|
-
function resolve (dir, file = '') {
|
|
5
|
-
return path.resolve(__dirname, '../', dir, file)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
9
|
-
mode: 'production',
|
|
10
|
-
entry: resolve('src/index.tsx'),
|
|
11
|
-
output: {
|
|
12
|
-
filename: 'guard.min.js',
|
|
13
|
-
path: resolve('dist/global'),
|
|
14
|
-
library: {
|
|
15
|
-
name: 'GuardFactory',
|
|
16
|
-
type: 'global'
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
resolve: {
|
|
20
|
-
extensions: ['.ts', '.tsx', '.js']
|
|
21
|
-
},
|
|
22
|
-
module: {
|
|
23
|
-
rules: [
|
|
24
|
-
{
|
|
25
|
-
test: /\.css$/,
|
|
26
|
-
use: [MiniCssExtractPlugin.loader, 'css-loader']
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
test: /\.tsx?$/,
|
|
30
|
-
use: 'ts-loader',
|
|
31
|
-
exclude: /node_modules/
|
|
32
|
-
}
|
|
33
|
-
]
|
|
34
|
-
},
|
|
35
|
-
plugins: [
|
|
36
|
-
new MiniCssExtractPlugin({
|
|
37
|
-
filename: 'guard.min.css'
|
|
38
|
-
})
|
|
39
|
-
]
|
|
40
|
-
}
|