@tsingroc/tsingroc-components 5.0.0-alpha.24 → 5.0.0-alpha.26
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.
|
@@ -21,7 +21,20 @@ export function LoginCheck(props) {
|
|
|
21
21
|
return () => sessionStore.addEventListener(onChange);
|
|
22
22
|
}, () => sessionStore.session);
|
|
23
23
|
const [status, setStatus] = useState(session ? "loaded" : "loading");
|
|
24
|
-
const
|
|
24
|
+
const startLoading = useEffectEvent(async () => {
|
|
25
|
+
try {
|
|
26
|
+
onBeforeGetSession?.();
|
|
27
|
+
void (await sessionStore.get());
|
|
28
|
+
} finally {
|
|
29
|
+
setStatus("loaded");
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (status === "loading") {
|
|
34
|
+
startLoading();
|
|
35
|
+
}
|
|
36
|
+
}, [status]);
|
|
37
|
+
const onSessionStoreEvent = useEffectEvent(async event => {
|
|
25
38
|
switch (event.type) {
|
|
26
39
|
case "failed":
|
|
27
40
|
onFailed?.(event.reason);
|
|
@@ -34,6 +47,8 @@ export function LoginCheck(props) {
|
|
|
34
47
|
break;
|
|
35
48
|
case "invalidated":
|
|
36
49
|
onInvalidated?.(event.reason);
|
|
50
|
+
onBeforeGetSession?.();
|
|
51
|
+
void (await sessionStore.get());
|
|
37
52
|
break;
|
|
38
53
|
}
|
|
39
54
|
});
|
|
@@ -41,18 +56,5 @@ export function LoginCheck(props) {
|
|
|
41
56
|
sessionStore.addEventListener(onSessionStoreEvent);
|
|
42
57
|
return () => sessionStore.removeEventListener(onSessionStoreEvent);
|
|
43
58
|
}, [sessionStore]);
|
|
44
|
-
const startLoading = useEffectEvent(async () => {
|
|
45
|
-
try {
|
|
46
|
-
onBeforeGetSession?.();
|
|
47
|
-
void (await sessionStore.get());
|
|
48
|
-
} finally {
|
|
49
|
-
setStatus("loaded");
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (status === "loading") {
|
|
54
|
-
startLoading();
|
|
55
|
-
}
|
|
56
|
-
}, [status]);
|
|
57
59
|
return status === "loading" ? loading : session ? children : failed;
|
|
58
60
|
}
|
|
@@ -48,8 +48,8 @@ export declare class SessionStore {
|
|
|
48
48
|
*
|
|
49
49
|
* - validated:会话首次验证成功。
|
|
50
50
|
* - revalidated:会话重新验证成功。
|
|
51
|
-
* - failed:
|
|
52
|
-
* - invalidated
|
|
51
|
+
* - failed: 会话创建失败。
|
|
52
|
+
* - invalidated:会话验证失败或者被手动终止。
|
|
53
53
|
*/
|
|
54
54
|
export type SessionStoreEvent = {
|
|
55
55
|
type: "validated" | "revalidated";
|
|
@@ -72,7 +72,7 @@ export class SessionStore {
|
|
|
72
72
|
let cancelled = false;
|
|
73
73
|
const promise = this.#validate(state).catch(err => {
|
|
74
74
|
this.#updateAndNotify(null, {
|
|
75
|
-
type: "
|
|
75
|
+
type: "invalidated",
|
|
76
76
|
reason: err
|
|
77
77
|
});
|
|
78
78
|
throw err;
|
|
@@ -189,6 +189,6 @@ export class SessionStore {
|
|
|
189
189
|
*
|
|
190
190
|
* - validated:会话首次验证成功。
|
|
191
191
|
* - revalidated:会话重新验证成功。
|
|
192
|
-
* - failed:
|
|
193
|
-
* - invalidated
|
|
192
|
+
* - failed: 会话创建失败。
|
|
193
|
+
* - invalidated:会话验证失败或者被手动终止。
|
|
194
194
|
*/
|