Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

auth-test.tsx 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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: any = await getSession(context)
  50. const handle = session?.user?.login
  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(
  55. (sponsor: { handle: string }) => sponsor.handle === handle
  56. )
  57. console.log(
  58. session,
  59. handle,
  60. sponsors.map((sponsor: any) => sponsor.handle)
  61. )
  62. return {
  63. props: {
  64. isOwner: session?.user?.email === 'steveruizok@gmail.com',
  65. isSponsor: sponsor !== undefined,
  66. ssrSession: session,
  67. },
  68. }
  69. }