| Auth on view content
This commit is contained in:
parent
e4f3ddb6cd
commit
a9111959cd
|
|
@ -7,6 +7,7 @@ import { usePurchaseContent, useViewContent } from "~/shared/services/content";
|
||||||
import { fromNanoTON } from "~/shared/utils";
|
import { fromNanoTON } from "~/shared/utils";
|
||||||
import {useCallback, useEffect, useMemo} from "react";
|
import {useCallback, useEffect, useMemo} from "react";
|
||||||
import { AudioPlayer } from "~/shared/ui/audio-player";
|
import { AudioPlayer } from "~/shared/ui/audio-player";
|
||||||
|
import {useAuth} from "~/shared/services/auth";
|
||||||
|
|
||||||
export const ViewContentPage = () => {
|
export const ViewContentPage = () => {
|
||||||
const WebApp = useWebApp();
|
const WebApp = useWebApp();
|
||||||
|
|
@ -17,13 +18,18 @@ export const ViewContentPage = () => {
|
||||||
|
|
||||||
const [tonConnectUI] = useTonConnectUI();
|
const [tonConnectUI] = useTonConnectUI();
|
||||||
|
|
||||||
|
const auth = useAuth();
|
||||||
|
|
||||||
|
|
||||||
const handleBuyContent = useCallback(async () => {
|
const handleBuyContent = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
if (!tonConnectUI.connected) {
|
if (!tonConnectUI.connected) {
|
||||||
await tonConnectUI.openModal();
|
await tonConnectUI.openModal();
|
||||||
return;
|
await auth.mutateAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await auth.mutateAsync();
|
||||||
|
|
||||||
const contentResponse = await purchaseContent({
|
const contentResponse = await purchaseContent({
|
||||||
content_address: content?.data?.encrypted?.cid,
|
content_address: content?.data?.encrypted?.cid,
|
||||||
license_type: "resale",
|
license_type: "resale",
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,9 @@ export const useAuth = () => {
|
||||||
console.error("Error in authentication request: ", error);
|
console.error("Error in authentication request: ", error);
|
||||||
throw new Error("Failed to authenticate.");
|
throw new Error("Failed to authenticate.");
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
void tonConnectUI.disconnect();
|
||||||
|
localStorage.removeItem(sessionStorageKey)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Loading…
Reference in New Issue