add oauth app connected

This commit is contained in:
lendry
2026-06-26 10:49:34 +03:00
parent d5e6b58955
commit b81c0cedbb
18 changed files with 838 additions and 59 deletions

View File

@@ -1,6 +1,6 @@
'use client';
import { useCallback, useEffect, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import { LayoutGrid, Loader2, Send, X } from 'lucide-react';
import { BotMessageKeyboard } from '@/components/chat/bot-message-keyboard';
import { BotChatMessageContextMenu } from '@/components/chat/bot-chat-message-context-menu';
@@ -13,6 +13,7 @@ import {
fetchBotChatMessages,
sendBotMessage
} from '@/lib/api';
import { postEmbeddedAuthToIframe } from '@/lib/embedded-auth-bridge';
import { extractMessageReplyMarkup, serializeInlineKeyboardMarkup } from '@/lib/bot-reply-markup';
import { resolveComposerMenuButton, type ComposerMenuButton } from '@/lib/bot-menu-button';
import { cn } from '@/lib/utils';
@@ -279,6 +280,7 @@ export function FamilyBotChat({
<BotMiniAppSheet
url={internalMiniAppUrl}
title={composerMenuButton?.text ?? 'Mini App'}
authToken={token}
onClose={() => setInternalMiniAppUrl(null)}
/>
</div>
@@ -288,10 +290,41 @@ export function FamilyBotChat({
interface BotMiniAppSheetProps {
url: string | null;
title?: string;
authToken?: string | null;
authRefreshToken?: string | null;
authSessionId?: string | null;
onClose: () => void;
}
export function BotMiniAppSheet({ url, title = 'Mini App', onClose }: BotMiniAppSheetProps) {
export function BotMiniAppSheet({
url,
title = 'Mini App',
authToken,
authRefreshToken,
authSessionId,
onClose
}: BotMiniAppSheetProps) {
const iframeRef = useRef<HTMLIFrameElement>(null);
const pushAuthToIframe = useCallback(() => {
if (!iframeRef.current || !authToken) return;
postEmbeddedAuthToIframe(iframeRef.current, {
token: authToken,
refreshToken: authRefreshToken,
sessionId: authSessionId
});
}, [authRefreshToken, authSessionId, authToken]);
useEffect(() => {
function handleMessage(event: MessageEvent) {
if (event.origin !== window.location.origin) return;
if (event.data?.type !== 'lendry-id-embedded-auth-request') return;
pushAuthToIframe();
}
window.addEventListener('message', handleMessage);
return () => window.removeEventListener('message', handleMessage);
}, [pushAuthToIframe]);
if (!url) return null;
return (
<div className="fixed inset-0 z-[70] flex items-end justify-center bg-black/40 p-4 sm:items-center">
@@ -302,7 +335,14 @@ export function BotMiniAppSheet({ url, title = 'Mini App', onClose }: BotMiniApp
<X className="h-4 w-4" />
</Button>
</div>
<iframe src={url} title={title} className="min-h-0 flex-1 border-0" allow="clipboard-read; clipboard-write" />
<iframe
ref={iframeRef}
src={url}
title={title}
className="min-h-0 flex-1 border-0"
allow="clipboard-read; clipboard-write"
onLoad={pushAuthToIframe}
/>
</div>
</div>
);