@openstack_dev/gatsby-theme-marketing-oif-core 1.0.35-beta.5 → 1.0.35
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/.nvmrc +1 -1
- package/gatsby-browser.js +2 -5
- package/gatsby-ssr.js +3 -7
- package/package.json +1 -1
- package/src/components/AuthBootstrap.js +37 -36
- package/src/content/site-settings/index.json +1 -1
- package/src/state/ReduxWrapper.js +11 -20
- package/src/state/store.js +26 -27
- package/src/utils/url.js +2 -1
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
22
|
package/gatsby-browser.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ReduxWrapper } from "./src/state/ReduxWrapper";
|
|
1
|
+
import { ReduxWrapperWithCacheProvider } from "./src/state/ReduxWrapper";
|
|
3
2
|
|
|
4
|
-
export const wrapRootElement =
|
|
5
|
-
<ReduxWrapper element={element} />
|
|
6
|
-
);
|
|
3
|
+
export const wrapRootElement = ReduxWrapperWithCacheProvider;
|
package/gatsby-ssr.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
1
|
import { JSDOM } from "jsdom";
|
|
4
2
|
import { XMLHttpRequest } from "xmlhttprequest";
|
|
5
|
-
import { HeadComponents } from "./src/components/head-components";
|
|
6
3
|
import { ReduxWrapper } from "./src/state/ReduxWrapper";
|
|
4
|
+
import { HeadComponents } from "./src/components/head-components";
|
|
7
5
|
|
|
8
6
|
export const onRenderBody = ({ setHeadComponents }) => {
|
|
9
7
|
if (process.env.NODE_ENV === "production") {
|
|
@@ -11,9 +9,7 @@ export const onRenderBody = ({ setHeadComponents }) => {
|
|
|
11
9
|
}
|
|
12
10
|
};
|
|
13
11
|
|
|
14
|
-
export const wrapRootElement =
|
|
15
|
-
<ReduxWrapper element={element} />
|
|
16
|
-
);
|
|
12
|
+
export const wrapRootElement = ReduxWrapper;
|
|
17
13
|
|
|
18
14
|
// build enabler polyfills
|
|
19
15
|
global.dom = new JSDOM("...");
|
|
@@ -23,7 +19,7 @@ global.navigator = global.window.navigator;
|
|
|
23
19
|
global.window.matchMedia = () => ({
|
|
24
20
|
matches: false,
|
|
25
21
|
addListener: () => {},
|
|
26
|
-
removeListener: () => {}
|
|
22
|
+
removeListener: () => {},
|
|
27
23
|
});
|
|
28
24
|
|
|
29
25
|
global.XMLHttpRequest = XMLHttpRequest;
|
package/package.json
CHANGED
|
@@ -7,46 +7,47 @@ export default function AuthBootstrap() {
|
|
|
7
7
|
const isLoggedUser = useSelector(
|
|
8
8
|
(state) => state.loggedUserState.isLoggedUser
|
|
9
9
|
);
|
|
10
|
+
const rehydrated = useSelector((state) => state._persist?.rehydrated);
|
|
10
11
|
const ranRef = useRef(false);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (typeof email === "string" && /\S+@\S+\.\S+/.test(email)) {
|
|
33
|
-
doLoginBasicLogin(getBackURL(), email);
|
|
34
|
-
}
|
|
35
|
-
} catch (err) {
|
|
36
|
-
if (err?.name !== "AbortError") {
|
|
37
|
-
console.error("AuthBootstrap whoami failed", err);
|
|
38
|
-
}
|
|
12
|
+
const MIN_EMAIL_LENGTH = 3;
|
|
13
|
+
|
|
14
|
+
const checkLoginStatus = async () => {
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetch("/oidc/session/whoami", {
|
|
17
|
+
method: "GET",
|
|
18
|
+
credentials: "same-origin"
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (!response.ok) return;
|
|
22
|
+
const data = await response.json();
|
|
23
|
+
if (
|
|
24
|
+
data.email &&
|
|
25
|
+
typeof data.email === "string" &&
|
|
26
|
+
data.email.includes("@") &&
|
|
27
|
+
data.email.includes(".") &&
|
|
28
|
+
data.email.length > MIN_EMAIL_LENGTH
|
|
29
|
+
) {
|
|
30
|
+
ranRef.current = true;
|
|
31
|
+
doLoginBasicLogin(getBackURL(), data.email);
|
|
32
|
+
return;
|
|
39
33
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
console.warn("Invalid or missing email in login response:", data.email);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error(
|
|
37
|
+
"Failed to check login status. Possible network error or invalid response.",
|
|
38
|
+
{
|
|
39
|
+
error,
|
|
40
|
+
attemptedUrl: "/oidc/session/whoami"
|
|
41
|
+
}
|
|
42
|
+
);
|
|
46
43
|
}
|
|
44
|
+
};
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (rehydrated !== undefined && !rehydrated) return; // Only wait if persist exists
|
|
48
|
+
if (isLoggedUser || ranRef.current) return;
|
|
49
|
+
checkLoginStatus();
|
|
50
|
+
}, [rehydrated, isLoggedUser]);
|
|
50
51
|
|
|
51
52
|
return null;
|
|
52
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{
|
|
1
|
+
{"staticJsonFilesBuildTime":[],"lastBuild":1773945801847}
|
|
@@ -2,34 +2,25 @@ import * as React from "react";
|
|
|
2
2
|
import { Provider } from "react-redux";
|
|
3
3
|
import { PersistGate } from "redux-persist/integration/react";
|
|
4
4
|
import { CacheProvider } from "@emotion/react";
|
|
5
|
-
|
|
6
|
-
import { store, getPersistor } from "./store";
|
|
5
|
+
import { store, persistor } from "./store";
|
|
7
6
|
import createEmotionCache from "../utils/createEmotionCache";
|
|
8
7
|
import AuthBootstrap from "../components/AuthBootstrap";
|
|
9
8
|
|
|
10
|
-
const cache = createEmotionCache();
|
|
11
|
-
|
|
12
9
|
export function ReduxWrapper({ element }) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
return (
|
|
11
|
+
<Provider store={store}>
|
|
12
|
+
<PersistGate persistor={persistor}>{() => element}</PersistGate>
|
|
13
|
+
</Provider>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
18
16
|
|
|
17
|
+
export function ReduxWrapperWithCacheProvider({ element }) {
|
|
18
|
+
const cache = createEmotionCache();
|
|
19
19
|
return (
|
|
20
20
|
<CacheProvider value={cache}>
|
|
21
21
|
<Provider store={store}>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<>
|
|
25
|
-
<AuthBootstrap />
|
|
26
|
-
{element}
|
|
27
|
-
</>
|
|
28
|
-
</PersistGate>
|
|
29
|
-
) : (
|
|
30
|
-
// first render SSR === Client
|
|
31
|
-
element
|
|
32
|
-
)}
|
|
22
|
+
<AuthBootstrap />
|
|
23
|
+
<PersistGate persistor={persistor}>{() => element}</PersistGate>
|
|
33
24
|
</Provider>
|
|
34
25
|
</CacheProvider>
|
|
35
26
|
);
|
package/src/state/store.js
CHANGED
|
@@ -1,40 +1,39 @@
|
|
|
1
1
|
import { applyMiddleware, compose, createStore } from "redux";
|
|
2
2
|
import { persistCombineReducers, persistStore } from "redux-persist";
|
|
3
|
+
import storage from "redux-persist/lib/storage";
|
|
3
4
|
import thunk from "redux-thunk";
|
|
4
|
-
import * as reducers from "../reducers";
|
|
5
|
-
|
|
6
|
-
const isBrowser = typeof window !== "undefined";
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
getItem: () => Promise.resolve(null),
|
|
10
|
-
setItem: () => Promise.resolve(),
|
|
11
|
-
removeItem: () => Promise.resolve()
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const storage = isBrowser
|
|
15
|
-
? require("redux-persist/lib/storage").default
|
|
16
|
-
: createNoopStorage();
|
|
6
|
+
import * as reducers from "../reducers";
|
|
17
7
|
|
|
8
|
+
// Get from process.env because window is not set yet
|
|
18
9
|
const clientId = process.env.GATSBY_OAUTH2_CLIENT_ID;
|
|
19
10
|
|
|
20
|
-
const config = {
|
|
21
|
-
|
|
11
|
+
const config = {
|
|
12
|
+
key: `root_${clientId}`,
|
|
13
|
+
storage,
|
|
14
|
+
blacklist: [
|
|
15
|
+
// this will be not saved to persistent storage see
|
|
16
|
+
// https://github.com/rt2zz/redux-persist#blacklist--whitelist
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const states = {
|
|
21
|
+
loggedUserState: reducers.loggedUserReducer,
|
|
22
|
+
};
|
|
22
23
|
|
|
23
|
-
const composeEnhancers =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
: compose;
|
|
24
|
+
const composeEnhancers = typeof window === "object" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
|
|
25
|
+
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
|
|
26
|
+
: compose;
|
|
27
27
|
|
|
28
28
|
const enhancer = composeEnhancers(applyMiddleware(thunk));
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
// Create store with persistor
|
|
31
|
+
export const { store, persistor } = (() => {
|
|
32
|
+
const persistedReducers = persistCombineReducers(config, states);
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
const store = createStore(persistedReducers, enhancer);
|
|
35
|
+
const onRehydrateComplete = () => {};
|
|
36
|
+
const persistor = persistStore(store, null, onRehydrateComplete);
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export const getPersistor = () => {
|
|
37
|
-
if (!isBrowser) return null;
|
|
38
|
-
if (!_persistor) _persistor = persistStore(store);
|
|
39
|
-
return _persistor;
|
|
40
|
-
};
|
|
38
|
+
return { store, persistor };
|
|
39
|
+
})();
|
package/src/utils/url.js
CHANGED