diff --git a/src/pages/view-content/index.tsx b/src/pages/view-content/index.tsx index 3a084db..5b24fbb 100644 --- a/src/pages/view-content/index.tsx +++ b/src/pages/view-content/index.tsx @@ -7,6 +7,7 @@ import { usePurchaseContent, useViewContent } from "~/shared/services/content"; import { fromNanoTON } from "~/shared/utils"; import {useCallback, useEffect, useMemo} from "react"; import { AudioPlayer } from "~/shared/ui/audio-player"; +import {useAuth} from "~/shared/services/auth"; export const ViewContentPage = () => { const WebApp = useWebApp(); @@ -17,13 +18,18 @@ export const ViewContentPage = () => { const [tonConnectUI] = useTonConnectUI(); + const auth = useAuth(); + + const handleBuyContent = useCallback(async () => { try { if (!tonConnectUI.connected) { await tonConnectUI.openModal(); - return; + await auth.mutateAsync(); } + await auth.mutateAsync(); + const contentResponse = await purchaseContent({ content_address: content?.data?.encrypted?.cid, license_type: "resale", diff --git a/src/shared/services/auth/index.ts b/src/shared/services/auth/index.ts index 23e2454..0f6d859 100644 --- a/src/shared/services/auth/index.ts +++ b/src/shared/services/auth/index.ts @@ -84,6 +84,9 @@ export const useAuth = () => { console.error("Error in authentication request: ", error); throw new Error("Failed to authenticate."); }); + } else { + void tonConnectUI.disconnect(); + localStorage.removeItem(sessionStorageKey) } }); }; \ No newline at end of file