Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

auth-test.tsx 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import Head from 'next/head'
  2. import { signIn, signOut, getSession, useSession } from 'next-auth/client'
  3. import { GetServerSidePropsContext } from 'next'
  4. export default function Home({
  5. ssrSession,
  6. isOwner,
  7. isSponsor,
  8. }: {
  9. isOwner: boolean
  10. isSponsor: boolean
  11. ssrSession: any
  12. }) {
  13. const [session, loading] = useSession()
  14. return (
  15. <>
  16. <Head>
  17. <title>tldraw</title>
  18. </Head>
  19. <div>
  20. <button onClick={() => signIn()}>Sign In</button>
  21. <button onClick={() => signOut()}>Sign Out</button>
  22. <p>{loading && 'Loading...'}</p>
  23. <pre>{JSON.stringify(session, null, 2)}</pre>
  24. <p>Is owner? {isOwner.toString()}</p>
  25. <p>Is sponsor? {isSponsor.toString()}</p>
  26. {isSponsor ? (
  27. <p>
  28. <b>Hey, thanks for sponsoring me!</b>
  29. </p>
  30. ) : (
  31. <p>
  32. <b>
  33. This site is just for my github sponsors.{' '}
  34. <a
  35. href="https://github.com/sponsors/steveruizok"
  36. target="_blank"
  37. rel="noopener noreferrer"
  38. >
  39. Sponsor here!
  40. </a>
  41. </b>
  42. </p>
  43. )}
  44. </div>
  45. </>
  46. )
  47. }
  48. export async function getServerSideProps(context: GetServerSidePropsContext) {
  49. const session = await getSession(context)
  50. const image = session?.user?.image
  51. const sponsors = await fetch(
  52. 'https://sponsors.trnck.dev/sponsors/steveruizok'
  53. ).then((d) => d.json().then((d) => d.sponsors))
  54. const sponsor = sponsors.some((sponsor: any) => sponsor.avatar === image)
  55. console.log(
  56. session?.user,
  57. image,
  58. sponsors.map((sponsor: any) => sponsor.avatar)
  59. )
  60. return {
  61. props: {
  62. isOwner: session?.user?.email === 'steveruizok@gmail.com',
  63. isSponsor: sponsor,
  64. ssrSession: session,
  65. },
  66. }
  67. }