'use client'; import 'react-loading-skeleton/dist/skeleton.css'; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faSpinner, faCheckCircle, faXmarkCircle } from "@fortawesome/free-solid-svg-icons"; import { useMutation, useQueryClient } from "@tanstack/react-query"; // import { updateIsUsernamePublic } from "./hooks/updateProfile"; import { useQuery } from '@tanstack/react-query'; import ProtectedRoute from "../components/protected-route"; import VibrateTest from "../components/vibrate-test"; import { useSession } from "next-auth/react" import { LoginButton, LogoutButton } from "../components/auth-buttons"; import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'; import Link from 'next/link'; import { useEffect } from 'react'; import { useState } from 'react'; import { fetchPatreonCurrentlyEntitledTiers } from './hooks/patreonCurrentlyEntitledTiers'; import { Spinner } from '../components/spinner'; import { signIn, signOut } from "next-auth/react"; export default function Page() { const queryClient = useQueryClient() // const sessionContext = Session.useSessionContext() // if (sessionContext.loading) { // return // } const { data, status, update } = useSession() async function renewJwt() { await signOut({ redirect: false }); await signIn("keycloak", { redirect: false }); } // const { data: patreonTier, isPending, refetch } = useQuery({ // queryKey: ['user/tier'], // queryFn: () => fetchPatreonCurrentlyEntitledTiers(), // }) // const keycloakGroupQuery = useQuery({ // queryKey: ['user/group'], // queryFn: () => fetchKeycloakGroup() // }) // const attributesMutation = useMutation({ // mutationFn: updateIsUsernamePublic, // mutationKey: ['user/attributes'], // onSuccess: () => queryClient.invalidateQueries({ queryKey: ['user/attributes'] }) // }) // const metadataQuery = useQuery({ // queryKey: ['user/metadata'], // queryFn: () => fetchMetadata() // }) // const [ isUsernamePublic, setIsUsernamePublic ] = useState() // const [ username, setUsername ] = useState('') // useEffect(() => { // if (metadataQuery.data?.metadata) { // setUsername(formatPatronUsername(metadataQuery.data.metadata.first_name, metadataQuery.data.metadata.last_name)) // setIsUsernamePublic(metadataQuery.data.metadata.isUsernamePublic) // } // }, [metadataQuery.data]) const isUsernamePublic = (data?.profile?.username_visibility === 'public') const [isGo, setIsGo] = useState() // useEffect(() => { // const fetchData = async () => { // const res = await fetch(`${process.env.KEYCLOAK_URL}/protocol/openid-connect/token`, { // method: 'POST', // headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, // body: new URLSearchParams({ // client_id: process.env.KEYCLOAK_CLIENT_ID, // client_secret: process.env.KEYCLOAK_CLIENT_SECRET, // grant_type: 'refresh_token', // refresh_token: session.refreshToken, // }), // }); // const data = await res.json(); // if (res.ok) { // // Update session with new token // session.accessToken = data.access_token; // session.refreshToken = data.refresh_token; // res.status(200).json(session); // } else { // res.status(400).json({ error: 'Token refresh failed' }); // } // } // fetchData(); // }, [isGo]); return (
{/* {(metadataQuery.isPending) && } */}

Debug section

{/* {(isPending) ? Syncronizing Patron entitlements... : Patreon entitlements synced.} */} {/*

metadataQuery as follows

*/} {/*
{JSON.stringify(metadataQuery.data, null, 2)}
*/}

session as follows

{JSON.stringify(data, null, 2)}
{(status === 'unauthenticated') && } {/* */}
{(data?.user) &&

Profile

{/*

{username}

*/}

{data?.user?.name}

{/*

Patronage

You belong to the {patreonTier} tier. Thank you!

*/}

Patron Perks

Test Perk (not real)

Hey look at you, you're granted access to this perk!

Website Shoutout

{isUsernamePublic && {data.user.name} will be displayed on the /patrons page} {!isUsernamePublic && Your username will be hidden from the /patrons page due to your privacy setting.} {/* Users can update privacy pref at https://keycloak.fp.sbtp.xyz/realms/futureporn/account/ */}

Premium Content Delivery Network (CDN1)

You have access to Futureporn's Premium CDN for reliable video playback

Economy Content Delivery Network (CDN2)

You have access to Futureporn's Economy CDN for basic video playback

Vibrate (test)

}
) // if (metadataQuery.isPending) return ; // return
{JSON.stringify(metadataQuery.data, null, 2)}
// return

@todo

// if (!isPending) return ; // if (!data) return

there is no data

; // if (!data?.metadata) return

there is no data.metadata

; // const { first_name, last_name } = data.metadata // const username = formatPatronUsername(first_name, last_name) // const { metadata } = data || {} // const { isUsernamePublic } = metadata // return ( // <> //
//
//

Profile

//
//
Username
//

// {isPending && // // // // } // {!isPending &&

{username}

} //

//
//
//
User ID
//
//

{sessionContext.userId}

//
//
//

Patron Perks

//

Website Shoutout

// //
// Display {(!!username) ? username : } publicly? // attributesMutation.mutate({ isUsernamePublic: evt.target.checked })}/> // {(attributesMutation.status === 'success') && } // {(attributesMutation.status === 'pending') && } // {(attributesMutation.status === 'error') && } //
//
//

Content Delivery Network (CDN)

// //

You have access to Futureporn's CDN for reliable video playback

//
//

Vibrate (test)

// //
//
// // ) }