@authing/native-js-ui-components 2.4.54 → 2.4.55
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/lib/index.d.ts +5 -4
- package/lib/index.min.css +1 -1
- package/lib/index.min.js +1 -1
- package/package.json +3 -3
- package/src/App.tsx +24 -20
- package/src/components/AuthingGuard/index.tsx +47 -55
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authing/native-js-ui-components",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.55",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "lib/index.min.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@authing/react-ui-components": "^2.4.
|
|
8
|
+
"@authing/react-ui-components": "^2.4.55",
|
|
9
9
|
"react": "16.14.0",
|
|
10
10
|
"react-dom": "16.14.0"
|
|
11
11
|
},
|
|
@@ -166,5 +166,5 @@
|
|
|
166
166
|
"webpack-manifest-plugin": "2.2.0",
|
|
167
167
|
"workbox-webpack-plugin": "5.1.4"
|
|
168
168
|
},
|
|
169
|
-
"gitHead": "
|
|
169
|
+
"gitHead": "8c8162fd4a91c1d1376bf68d4592f90572cc3a7e"
|
|
170
170
|
}
|
package/src/App.tsx
CHANGED
|
@@ -1,32 +1,36 @@
|
|
|
1
|
-
import React, { useEffect } from
|
|
2
|
-
import
|
|
3
|
-
import { AuthingGuard, GuardMode } from
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import "./App.css";
|
|
3
|
+
import { AuthingGuard, GuardMode } from "./components";
|
|
4
4
|
|
|
5
5
|
function App() {
|
|
6
6
|
useEffect(() => {
|
|
7
|
-
const guard = new AuthingGuard(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const guard = new AuthingGuard(
|
|
8
|
+
"6191cf610f772aa56dc70637",
|
|
9
|
+
{
|
|
10
|
+
target: ".App",
|
|
11
|
+
appHost: "https://core.dev2.authing-inc.co/",
|
|
12
|
+
mode: GuardMode.Modal,
|
|
13
|
+
},
|
|
14
|
+
"6194a41abf23c1d5268b362a"
|
|
15
|
+
);
|
|
12
16
|
|
|
13
17
|
// @ts-ignore
|
|
14
|
-
window.guard = guard
|
|
18
|
+
window.guard = guard;
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
guard.show();
|
|
17
21
|
|
|
18
|
-
guard.on(
|
|
19
|
-
console.log(
|
|
20
|
-
})
|
|
22
|
+
guard.on("load", (e: any) => {
|
|
23
|
+
console.log("加载啊", e);
|
|
24
|
+
});
|
|
21
25
|
|
|
22
|
-
guard.on(
|
|
26
|
+
guard.on("close", () => {
|
|
23
27
|
setTimeout(() => {
|
|
24
|
-
guard.show()
|
|
25
|
-
}, 2000)
|
|
26
|
-
})
|
|
27
|
-
}, [])
|
|
28
|
+
guard.show();
|
|
29
|
+
}, 2000);
|
|
30
|
+
});
|
|
31
|
+
}, []);
|
|
28
32
|
|
|
29
|
-
return <div className="App"></div
|
|
33
|
+
return <div className="App"></div>;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
export default App
|
|
36
|
+
export default App;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import ReactDOM from
|
|
3
|
-
import { AuthingGuard as ReactAuthingGuard } from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import ReactDOM from "react-dom";
|
|
3
|
+
import { AuthingGuard as ReactAuthingGuard } from "@authing/react-ui-components";
|
|
4
4
|
import {
|
|
5
5
|
User,
|
|
6
6
|
GuardMode,
|
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
GuardEventsHandlerKebab,
|
|
17
17
|
GuardEventsCamelToKebabMap,
|
|
18
18
|
AuthenticationClientOptions,
|
|
19
|
-
} from
|
|
20
|
-
import
|
|
19
|
+
} from "@authing/react-ui-components";
|
|
20
|
+
import "@authing/react-ui-components/lib/index.min.css";
|
|
21
21
|
|
|
22
22
|
export type {
|
|
23
23
|
User,
|
|
@@ -27,7 +27,7 @@ export type {
|
|
|
27
27
|
AuthenticationClient,
|
|
28
28
|
GuardEventsHandlerKebab,
|
|
29
29
|
AuthenticationClientOptions,
|
|
30
|
-
}
|
|
30
|
+
};
|
|
31
31
|
|
|
32
32
|
export {
|
|
33
33
|
GuardMode,
|
|
@@ -37,99 +37,91 @@ export {
|
|
|
37
37
|
initAuthClient,
|
|
38
38
|
RegisterMethods,
|
|
39
39
|
GuardEventsCamelToKebabMap,
|
|
40
|
-
}
|
|
40
|
+
};
|
|
41
41
|
|
|
42
42
|
export type EventListeners = {
|
|
43
|
-
[key in keyof GuardEventsHandlerKebab]: Exclude<
|
|
44
|
-
|
|
45
|
-
undefined
|
|
46
|
-
>[]
|
|
47
|
-
}
|
|
43
|
+
[key in keyof GuardEventsHandlerKebab]: Exclude<Required<GuardEventsHandlerKebab>[key], undefined>[];
|
|
44
|
+
};
|
|
48
45
|
|
|
49
46
|
export class AuthingGuard {
|
|
50
|
-
constructor(private appId: string, private config?: UserConfig) {
|
|
51
|
-
this.render()
|
|
47
|
+
constructor(private appId: string, private config?: UserConfig, private tenantId?: string) {
|
|
48
|
+
this.render();
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
static getGuardContainer(selector?: string | HTMLElement) {
|
|
55
|
-
const defaultId =
|
|
52
|
+
const defaultId = "authing_guard_container";
|
|
56
53
|
|
|
57
54
|
if (!selector) {
|
|
58
|
-
let container = document.querySelector(`#${defaultId}`)
|
|
55
|
+
let container = document.querySelector(`#${defaultId}`);
|
|
59
56
|
if (!container) {
|
|
60
|
-
container = document.createElement(
|
|
61
|
-
container.id = defaultId
|
|
62
|
-
document.body.appendChild(container)
|
|
57
|
+
container = document.createElement("div");
|
|
58
|
+
container.id = defaultId;
|
|
59
|
+
document.body.appendChild(container);
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
return container
|
|
62
|
+
return container;
|
|
66
63
|
}
|
|
67
64
|
|
|
68
|
-
if (typeof selector ===
|
|
69
|
-
return document.querySelector(selector)
|
|
65
|
+
if (typeof selector === "string") {
|
|
66
|
+
return document.querySelector(selector);
|
|
70
67
|
}
|
|
71
68
|
|
|
72
|
-
return selector
|
|
69
|
+
return selector;
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
private visible = this.config?.mode === GuardMode.Modal ? false : true
|
|
72
|
+
private visible = this.config?.mode === GuardMode.Modal ? false : true;
|
|
76
73
|
|
|
77
|
-
private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce(
|
|
78
|
-
(acc,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
{} as EventListeners
|
|
84
|
-
)
|
|
74
|
+
private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce((acc, evtName) => {
|
|
75
|
+
return Object.assign({}, acc, {
|
|
76
|
+
[evtName]: [],
|
|
77
|
+
});
|
|
78
|
+
}, {} as EventListeners);
|
|
85
79
|
|
|
86
80
|
private render(cb?: () => void) {
|
|
87
|
-
const evts: GuardEventsHandler = Object.entries(
|
|
88
|
-
GuardEventsCamelToKebabMap
|
|
89
|
-
).reduce((acc, [reactEvt, nativeEvt]) => {
|
|
81
|
+
const evts: GuardEventsHandler = Object.entries(GuardEventsCamelToKebabMap).reduce((acc, [reactEvt, nativeEvt]) => {
|
|
90
82
|
return Object.assign({}, acc, {
|
|
91
83
|
[reactEvt]: (...rest: any) => {
|
|
92
|
-
if (nativeEvt ===
|
|
93
|
-
this.hide()
|
|
84
|
+
if (nativeEvt === "close") {
|
|
85
|
+
this.hide();
|
|
94
86
|
}
|
|
95
87
|
|
|
96
88
|
// TODO 返回最后一个执行函数的值,实际应该只让监听一次
|
|
97
|
-
return
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
89
|
+
return (
|
|
90
|
+
this.eventListeners[nativeEvt]
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
.map((item: any) => {
|
|
93
|
+
return item(...rest);
|
|
94
|
+
})
|
|
95
|
+
.slice(-1)[0] ?? true
|
|
96
|
+
);
|
|
103
97
|
},
|
|
104
|
-
})
|
|
105
|
-
}, {} as GuardEventsHandler)
|
|
98
|
+
});
|
|
99
|
+
}, {} as GuardEventsHandler);
|
|
106
100
|
|
|
107
101
|
return ReactDOM.render(
|
|
108
102
|
<ReactAuthingGuard
|
|
109
103
|
{...evts}
|
|
110
104
|
appId={this.appId}
|
|
105
|
+
tenantId={this.tenantId}
|
|
111
106
|
config={this.config}
|
|
112
107
|
visible={this.visible}
|
|
113
108
|
/>,
|
|
114
109
|
AuthingGuard.getGuardContainer(this.config?.target),
|
|
115
110
|
cb
|
|
116
|
-
)
|
|
111
|
+
);
|
|
117
112
|
}
|
|
118
113
|
|
|
119
|
-
on<T extends keyof GuardEventsHandlerKebab>(
|
|
120
|
-
evt
|
|
121
|
-
handler: Exclude<GuardEventsHandlerKebab[T], undefined>
|
|
122
|
-
) {
|
|
123
|
-
this.eventListeners[evt]!.push(handler as any)
|
|
114
|
+
on<T extends keyof GuardEventsHandlerKebab>(evt: T, handler: Exclude<GuardEventsHandlerKebab[T], undefined>) {
|
|
115
|
+
this.eventListeners[evt]!.push(handler as any);
|
|
124
116
|
}
|
|
125
117
|
|
|
126
118
|
show() {
|
|
127
|
-
this.visible = true
|
|
128
|
-
this.render()
|
|
119
|
+
this.visible = true;
|
|
120
|
+
this.render();
|
|
129
121
|
}
|
|
130
122
|
|
|
131
123
|
hide() {
|
|
132
|
-
this.visible = false
|
|
133
|
-
this.render()
|
|
124
|
+
this.visible = false;
|
|
125
|
+
this.render();
|
|
134
126
|
}
|
|
135
127
|
}
|