@openstack_dev/gatsby-theme-marketing-oif-core 1.0.33-beta.3 → 1.0.35-beta.1
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/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useSelector } from "react-redux";
|
|
3
|
+
import { doLoginBasicLogin } from "openstack-uicore-foundation/lib/security/methods";
|
|
4
|
+
import { getBackURL } from "../utils/url";
|
|
5
|
+
|
|
6
|
+
export default function AuthBootstrap() {
|
|
7
|
+
const isLoggedUser = useSelector(
|
|
8
|
+
(state) => state.loggedUserState.isLoggedUser
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const checkLoginStatus = async () => {
|
|
12
|
+
try {
|
|
13
|
+
const response = await fetch("/oidc/session/whoami", {
|
|
14
|
+
method: "GET",
|
|
15
|
+
credentials: "same-origin"
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (response.ok) {
|
|
19
|
+
const data = await response.json();
|
|
20
|
+
if (
|
|
21
|
+
data.email &&
|
|
22
|
+
typeof data.email === "string" &&
|
|
23
|
+
/\S+@\S+\.\S+/.test(data.email)
|
|
24
|
+
) {
|
|
25
|
+
doLoginBasicLogin(getBackURL(), data.email);
|
|
26
|
+
} else {
|
|
27
|
+
console.warn(
|
|
28
|
+
"Invalid or missing email in login response:",
|
|
29
|
+
data.email
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error(
|
|
35
|
+
"Failed to check login status. Possible network error or invalid response.",
|
|
36
|
+
{
|
|
37
|
+
error,
|
|
38
|
+
attemptedUrl: "/oidc/session/whoami"
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!isLoggedUser) checkLoginStatus();
|
|
46
|
+
}, [isLoggedUser]);
|
|
47
|
+
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
@@ -4,6 +4,7 @@ import { PersistGate } from "redux-persist/integration/react";
|
|
|
4
4
|
import { CacheProvider } from "@emotion/react";
|
|
5
5
|
import { store, persistor } from "./store";
|
|
6
6
|
import createEmotionCache from "../utils/createEmotionCache";
|
|
7
|
+
import AuthBootstrap from "../components/AuthBootstrap";
|
|
7
8
|
|
|
8
9
|
export function ReduxWrapper({ element }) {
|
|
9
10
|
return (
|
|
@@ -14,10 +15,12 @@ export function ReduxWrapper({ element }) {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export function ReduxWrapperWithCacheProvider({ element }) {
|
|
17
|
-
const
|
|
18
|
+
const cacheRef = React.useRef(null);
|
|
19
|
+
if (!cacheRef.current) cacheRef.current = createEmotionCache();
|
|
18
20
|
return (
|
|
19
|
-
<CacheProvider value={
|
|
21
|
+
<CacheProvider value={cacheRef.current}>
|
|
20
22
|
<Provider store={store}>
|
|
23
|
+
<AuthBootstrap />
|
|
21
24
|
<PersistGate persistor={persistor}>{() => element}</PersistGate>
|
|
22
25
|
</Provider>
|
|
23
26
|
</CacheProvider>
|