updating iframe auth handling

This commit is contained in:
2026-02-27 12:29:10 -06:00
parent 18c07725fc
commit b91eb2b639
3 changed files with 54 additions and 22 deletions
+5 -12
View File
@@ -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<EmbedAuthWrapperProps> = (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);
});