feature/IO-3255-simplified-parts-management -Checkpoint

This commit is contained in:
Dave Richer
2025-07-21 15:28:03 -04:00
parent dfa457e3c6
commit 0ac9bbd97c

View File

@@ -42,16 +42,19 @@ export function SignInComponent({ emailSignInStart, currentUser, signInError, se
} }
}, [currentUser, redirect, navigate]); }, [currentUser, redirect, navigate]);
// Add event listener for seamless login
useEffect(() => { useEffect(() => {
const handleSeamlessLogin = (event) => { const handleSeamlessLogin = (event) => {
const { email, password, origin: requestOrigin } = event.detail || {}; console.log("Received message event:", event); // Log the received message event
if (event.data?.type !== "seamlessLoginRequest") return; // Filter to only handle relevant messages
console.log("Received seamless login request:", event.data);
const { email, password } = event.data || {}; // Use event.data instead of event.detail
const requestOrigin = event.origin; // Use event.origin automatically
// Validate input // Validate input (rest of your code remains the same)
if (!email || !password) { if (!email || !password) {
window.parent.postMessage( window.parent.postMessage(
{ type: "seamlessLoginResponse", status: "error", message: "Email and password are required" }, { type: "seamlessLoginResponse", status: "error", message: "Email and password are required" },
requestOrigin || "*" // Use specific origin for security if known requestOrigin || "*"
); );
return; return;
} }
@@ -69,12 +72,10 @@ export function SignInComponent({ emailSignInStart, currentUser, signInError, se
window.parent.postMessage({ type: "seamlessLoginResponse", status: "login_attempted" }, requestOrigin || "*"); window.parent.postMessage({ type: "seamlessLoginResponse", status: "login_attempted" }, requestOrigin || "*");
}; };
// Add event listener for custom seamless login event window.addEventListener("message", handleSeamlessLogin); // Listen for "message"
window.addEventListener("seamlessLoginRequest", handleSeamlessLogin);
// Cleanup to remove the event listener on unmount
return () => { return () => {
window.removeEventListener("seamlessLoginRequest", handleSeamlessLogin); window.removeEventListener("message", handleSeamlessLogin);
}; };
}, [emailSignInStart, currentUser, navigate, redirect]); }, [emailSignInStart, currentUser, navigate, redirect]);