diff options
author | jose-donato <43375532+jose-donato@users.noreply.github.com> | 2024-01-17 15:16:34 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-17 15:16:34 +0000 |
commit | 54b6a2e22a5df4391683c651c2fec45a740a8141 (patch) | |
tree | 6f6a1a1b4b8a2aa31b9706014f4f8ffdda259bfe | |
parent | 7fd223d5911dfe8ed20c1c1101373116b83e985f (diff) |
fix: adds logic to check whther user is logged in on hub (#5941)
Co-authored-by: Luqman <luqazino@gmail.com>
-rw-r--r-- | website/src/theme/Root.tsx | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/website/src/theme/Root.tsx b/website/src/theme/Root.tsx index 3da7e8aff94..e95b4f961b1 100644 --- a/website/src/theme/Root.tsx +++ b/website/src/theme/Root.tsx @@ -1,6 +1,6 @@ -import React, { createContext, useContext, useEffect, useState } from "react"; -import posthog from "posthog-js"; import { useLocation } from "@docusaurus/router"; +import posthog from "posthog-js"; +import React, { createContext, useContext, useEffect, useState } from "react"; export const iFrameContext = createContext({ isIFrame: false, @@ -11,6 +11,7 @@ export const useIFrameContext = () => useContext(iFrameContext); export default function Root({ children }) { const [isIFrame, setIsIFrame] = useState(false); const [posthogLoaded, setPosthogLoaded] = useState(false); + const location = useLocation(); useEffect(() => { setIsIFrame(window?.self !== window?.top); if (window?.self !== window?.top) { @@ -28,7 +29,7 @@ export default function Root({ children }) { }, loaded: () => { setPosthogLoaded(true); - posthog.onFeatureFlags(function () { + posthog.onFeatureFlags(() => { if (!posthog.isFeatureEnabled("record-web", { send_event: false })) { posthog.stopSessionRecording(); console.log("Stopped session recording"); @@ -45,13 +46,25 @@ export default function Root({ children }) { }); }, []); - const location = useLocation(); - useEffect(() => { if (posthogLoaded) posthog.capture("$pageview"); }, [location.pathname, posthogLoaded]); + + useEffect(() => { + if (location.pathname.startsWith("/pro") || location.pathname.startsWith("/excel")) { + const cookie = document.cookie.split(";").find((c) => c.trim().startsWith("docs-login=")); + const payload = decodeURIComponent(cookie.split('=')[1].split('.')[0]); + if (isValidBase64(payload)) { + const decodedPayload = atob(decodeURIComponent(payload)); + // decide what we want to do whether the user is logged in or not + } else { + console.error('Invalid base64 string:', payload); + } + } + }, [location.pathname]) + return ( <iFrameContext.Provider value={{ @@ -62,3 +75,11 @@ export default function Root({ children }) { </iFrameContext.Provider> ); } + +function isValidBase64(str) { + try { + return btoa(atob(str)) == str; + } catch (err) { + return false; + } +}
\ No newline at end of file |