@tsingroc/tsingroc-components 5.0.0-alpha.24 → 5.0.0-alpha.25
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
|
}
|