feat: add non-interactive SSO login flow for embedded/iframe deployments (closes #69)

This commit is contained in:
Linus Rath
2026-03-21 20:45:19 +01:00
parent 7c3c3b5f7b
commit 83a0a1e235
18 changed files with 674 additions and 123 deletions
@@ -0,0 +1,34 @@
"use client";
import { useEffect } from "react";
import { isEmbedded, listenFromParent } from "@/lib/iframe-bridge";
import { useAuthStore } from "@/stores/auth-store";
import { useConfig } from "@/hooks/use-config";
export function EmbeddedBridgeProvider({ children }: { children: React.ReactNode }) {
const { parentOrigin, embeddedMode } = useConfig();
const logout = useAuthStore((s) => s.logout);
useEffect(() => {
if (!embeddedMode || !isEmbedded()) return;
const unsubscribe = listenFromParent((msg) => {
switch (msg.type) {
case "sso:trigger-login": {
// Navigate to login page to start SSO flow
const segments = window.location.pathname.split("/").filter(Boolean);
const locale = segments[0] || "en";
window.location.href = `/${locale}/login`;
break;
}
case "sso:trigger-logout":
logout();
break;
}
}, parentOrigin || undefined);
return unsubscribe;
}, [embeddedMode, parentOrigin, logout]);
return <>{children}</>;
}