diff --git a/src/App.tsx b/src/App.tsx index 01be75d..96266e7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -26,6 +26,7 @@ const App: Component = () => { onMount(() => { const removeListener = pb.authStore.onChange((token) => { + console.log('[DEBUG] pb.authStore.onChange fired, token present:', !!token); setIsAuthenticated(!!token); if (token) { initStore(); @@ -56,13 +57,22 @@ const App: Component = () => { }); }); - // Determine if we are in an embed route - const isEmbed = () => window.location.pathname.startsWith('/embed/'); - const embedView = () => { + // Determine if we are in an embed route (check both path and hash for compatibility) + const isEmbed = () => { const path = window.location.pathname; - if (path.includes('/notes')) return 'embed_notes'; - if (path.includes('/quick-add')) return 'embed_quick_add'; - return null; + const hash = window.location.hash; + const res = path.startsWith('/embed/') || hash.startsWith('#/embed/'); + console.log('[DEBUG] isEmbed check:', { res, path, hash, href: window.location.href }); + return res; + }; + + const getEmbedView = () => { + const fullPath = window.location.pathname + window.location.hash; + let view = null; + if (fullPath.includes('/notes')) view = 'embed_notes'; + else if (fullPath.includes('/quick-add')) view = 'embed_quick_add'; + console.log('[DEBUG] getEmbedView detected:', view, 'Full URL context:', fullPath); + return view; }; return ( @@ -89,10 +99,10 @@ const App: Component = () => {
}> - + - +
diff --git a/src/components/EmbedAuthWrapper.tsx b/src/components/EmbedAuthWrapper.tsx index 631baf4..cf21a75 100644 --- a/src/components/EmbedAuthWrapper.tsx +++ b/src/components/EmbedAuthWrapper.tsx @@ -1,6 +1,5 @@ import { type Component, type JSX, onMount, onCleanup, createSignal, Show } from "solid-js"; import { pb } from "@/lib/pocketbase"; -import { initStore } from "@/store"; interface EmbedAuthWrapperProps { children: JSX.Element; @@ -10,24 +9,18 @@ export const EmbedAuthWrapper: Component = (props) => { const [isHydrated, setIsHydrated] = createSignal(pb.authStore.isValid); const handleMessage = (event: MessageEvent) => { - // You might want to add origin validation here if you know the sibling app domains - // if (event.origin !== "https://sibling-app.com") return; - const { data } = event; + console.log('[DEBUG] EmbedAuthWrapper received message:', data?.type); if (data?.type === "TASGRID_AUTH" && data.token) { - console.log("Received TasGrid auth payload via postMessage"); - - // Hydrate PocketBase auth store + console.log("[DEBUG] Received TasGrid auth payload, hydrating..."); + // Save triggers pb.authStore.onChange, which App.tsx is already listening to and calling initStore() pb.authStore.save(data.token, data.user || null); - - // Re-initialize store with new auth context - initStore().then(() => { - setIsHydrated(true); - }); + setIsHydrated(true); } }; onMount(() => { + console.log('[DEBUG] EmbedAuthWrapper mounted. Initial isHydrated:', isHydrated()); window.addEventListener("message", handleMessage); }); diff --git a/test-embed.html b/test-embed.html index 5e5a2ca..4e3ac05 100644 --- a/test-embed.html +++ b/test-embed.html @@ -129,6 +129,35 @@ + +
+
+ Developer Integration Guide + +
+

1. Available Routes:

+
    +
  • /embed/notes: Renders the full notepad/editor.
  • +
  • /embed/quick-add: Renders a standalone task creation form.
  • +
+ +

2. Authentication Protocol:

+

The parent application must send a postMessage to the iframe immediately after the + iframe loads (or whenever auth state changes).

+
+iframe.contentWindow.postMessage({
+  type: "TASGRID_AUTH",
+  token: "YOUR_POCKETBASE_TOKEN",
+  user: { /* optional PB user record */ }
+}, "*");
+ +

3. Responsiveness:

+

Both routes are designed to be fluid. Ensure your iframe container has defined dimensions; the + content will expand to fill it.

+
+
+
@@ -138,7 +167,7 @@ Notes Embed /embed/notes
- +
@@ -147,7 +176,7 @@ Quick Add Embed /embed/quick-add
- +