@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 CHANGED
@@ -1 +1 @@
1
- 20.19.4
1
+ 22
package/gatsby-browser.js CHANGED
@@ -1,6 +1,3 @@
1
- import React from "react";
2
- import { ReduxWrapper } from "./src/state/ReduxWrapper";
1
+ import { ReduxWrapperWithCacheProvider } from "./src/state/ReduxWrapper";
3
2
 
4
- export const wrapRootElement = ({ element }) => (
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 = ({ element }) => (
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openstack_dev/gatsby-theme-marketing-oif-core",
3
- "version": "1.0.35-beta.5",
3
+ "version": "1.0.35",
4
4
  "description": "Base theme for Marketing Sites",
5
5
  "author": "smarcet",
6
6
  "keywords": [
@@ -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
- useEffect(() => {
13
- // already ran
14
- if (ranRef.current || isLoggedUser) return;
15
- ranRef.current = true;
16
-
17
- const controller = new AbortController();
18
-
19
- const run = async () => {
20
- try {
21
- const response = await fetch("/oidc/session/whoami", {
22
- method: "GET",
23
- credentials: "same-origin",
24
- signal: controller.signal
25
- });
26
-
27
- if (!response.ok) return;
28
-
29
- const data = await response.json();
30
- const email = data?.email;
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
- if (typeof window !== "undefined" && "requestIdleCallback" in window) {
43
- window.requestIdleCallback(run, { timeout: 1000 });
44
- } else {
45
- setTimeout(run, 0);
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
- return () => controller.abort();
49
- }, [isLoggedUser]);
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
- { "staticJsonFilesBuildTime": [], "lastBuild": 1740420798753 }
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
- const [persistor, setPersistor] = React.useState(null);
14
-
15
- React.useEffect(() => {
16
- setPersistor(getPersistor());
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
- {persistor ? (
23
- <PersistGate persistor={persistor} loading={null}>
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
  );
@@ -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
- const createNoopStorage = () => ({
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 = { key: `root_${clientId}`, storage };
21
- const states = { loggedUserState: reducers.loggedUserReducer };
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
- typeof window === "object" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
25
- ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
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
- const persistedReducers = persistCombineReducers(config, states);
30
+ // Create store with persistor
31
+ export const { store, persistor } = (() => {
32
+ const persistedReducers = persistCombineReducers(config, states);
31
33
 
32
- export const store = createStore(persistedReducers, enhancer);
34
+ const store = createStore(persistedReducers, enhancer);
35
+ const onRehydrateComplete = () => {};
36
+ const persistor = persistStore(store, null, onRehydrateComplete);
33
37
 
34
- // lazy persistor
35
- let _persistor = null;
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
@@ -1,7 +1,8 @@
1
1
  export const getBackURL = () => {
2
2
  let backUrl = "/";
3
3
  if (typeof window !== "undefined") {
4
- backUrl = window.location.pathname;
4
+ backUrl =
5
+ window.location.pathname + window.location.search + window.location.hash;
5
6
  }
6
7
  return backUrl;
7
8
  };