import Head from 'next/head'
import { signIn, signOut, getSession, useSession } from 'next-auth/client'
import { GetServerSidePropsContext } from 'next'
export default function Home({
ssrSession,
isOwner,
isSponsor,
}: {
isOwner: boolean
isSponsor: boolean
ssrSession: any
}) {
const [session, loading] = useSession()
return (
<>
tldraw
{loading && 'Loading...'}
{JSON.stringify(session, null, 2)}
Is owner? {isOwner.toString()}
Is sponsor? {isSponsor.toString()}
{isSponsor ? (
Hey, thanks for sponsoring me!
) : (
This site is just for my github sponsors.{' '}
Sponsor here!
)}
>
)
}
export async function getServerSideProps(context: GetServerSidePropsContext) {
const session = await getSession(context)
const image = session?.user?.image
const sponsors = await fetch(
'https://sponsors.trnck.dev/sponsors/steveruizok'
).then((d) => d.json().then((d) => d.sponsors))
const sponsor = sponsors.some((sponsor: any) => sponsor.avatar === image)
console.log(
session?.user,
image,
sponsors.map((sponsor: any) => sponsor.avatar)
)
return {
props: {
isOwner: session?.user?.email === 'steveruizok@gmail.com',
isSponsor: sponsor,
ssrSession: session,
},
}
}