[
  {
    "path": ".gitignore",
    "content": "# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.\n\n# .env file\n.env\n\n# dependencies\n/node_modules\n/.pnp\n.pnp.js\n\n# testing\n/coverage\n\n# next.js\n/.next/\n/out/\n\n# production\n/build\n\n# misc\n.DS_Store\n*.pem\n\n# debug\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n\n# local env files\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n.env.staging\n.env.production\n\n# vercel\n.vercel\n\n# Webstorm\n.idea\n.vscode\n\n# Local Netlify folder\n.netlify"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright 2021 PlanetScale, Inc.\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# Next.js Starter App for Netlify\n\n## Overview\n\nThis README will guide you in getting up and running with Next.js starter app with authentication [NextAuth.js](https://next-auth.js.org/) and deployed on Netlify. Immediately, you can allow users to sign up or login to your app, including a built-in admin panel with a users table (powered by [PlanetScale](https://planetscale.com)).\n\nWe have configured this template for you to one-click deploy directly to Netlify. Alternatively, you can manually deploy to your choice of hosting platform for Next.js applications. For more information on why we created this starter app, read me more in our [blog post](https://planetscale.com/blog/nextjs-netlify-planetscale-starter-app).\n\n[🖼 Live Demo](https://nextjs-planetscale-starter.netlify.app/)\n\n![Example login screen](https://cdn.sanity.io/images/f1avhira/production/9767f106ce5d17f93054ba6ee8a930c546283348-2874x1586.png)\n\n## 🥞 Stack\n\n- Framework - [Next.js v12](https://nextjs.org)\n- Language - [TypeScript](https://www.typescriptlang.org/)\n- Auth - [NextAuth.js](https://next-auth.js.org/)\n- Database - [PlanetScale](https://planetscale.com)\n- ORM - [Prisma](https://prisma.io)\n- Hosting - [Netlify](https://netlify.com)\n- Styling - [TailwindCSS](https://tailwindcss.com)\n\n## Getting Started\n\nTo follow along with this guide, you'll need the following:\n\n- A [free PlanetScale account](https://auth.planetscale.com/sign-up)\n- The [PlanetScale CLI](https://github.com/planetscale/cli#installation)\n- [Yarn](https://yarnpkg.com/getting-started/install)\n- [Node (LTS)](https://nodejs.org/en/)\n- A [free Netlify account](https://app.netlify.com/signup)\n\n### One-click Deploy with Netlify (recommended)\n\nThe one-click deploy button allows you to connect Netlify to your GitHub account to clone the nextjs-planetscale-starter repository and automatically deploy it. Be sure to sign up for a Netlify account before clicking the deploy button.\n\n[![Deploy to Netlify button](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/planetscale/nextjs-planetscale-starter)\n\nOnce you click the button, you'll be taken to Netlify’s direct deploy page with the pre-built project’s repository passed as a parameter in the URL. Click the \"Connect to GitHub\" button to authorize access.\n\nNext, you'll be asked to configure your site variables. For the Secret value, navigate to [https://generate-secret.now.sh/32](https://generate-secret.now.sh/32) to generate a secret and then paste that in. You can leave the Database URL and NextAuth URL values blank for now. Click \"Save & Deploy\".\n\nYour site will take about a minute to build and then you'll be taken to a settings page. A unique Netlify URL will be generated for the project. You can click that now to see your live site!\n\n**Important:** Once the site is deployed, [follow these steps](https://planetscale.com/docs/tutorials/nextjs-planetscale-netlify-template) to get your PlanetScale database up and running.\n\n> Note: If you do not follow the steps to get your database set up, you will see a 500 error on your live site.\n\n## Admin accounts\n\nAdmin accounts have access to `/admin`, which contains a user dashboard (powered by PlanetScale). This dashboard is a great starting place to build out an admin dashboard for your app.\n\n![Example users table](https://cdn.sanity.io/images/f1avhira/production/e2f1b5c5d47887315b2fa17f4039ee9c638e798e-2876x1588.png)\n\n## Caveats\n\nThis application is close to production ready, but there are a few things you will need to consider and implement.\n\n#### What's not in this starter app?\n\n- **Email Sending & Password Resets:**\nWe've left this implementation up to the user because we did not want to make adding an email provider a requirement. The default `VerificationToken` schema has the basics required for implementing sign up verification, or password reset requests.\n- **API Security:** Although NextAuth.js can be used for authentication, it does not provide authorization out of the box. The application comes with and example of protecting API routes using NextAuth.js. It does not cover things like making sure only administrators can access certain routes or making sure that only a user is able to update their account.\n- **Multiple admin accounts**\n"
  },
  {
    "path": "db/index.ts",
    "content": "import { PrismaClient } from \"@prisma/client\";\n\nexport * from \"@prisma/client\";\n\nlet prisma: PrismaClient;\n\nif (process.env.NODE_ENV === \"production\") {\n  prisma = new PrismaClient({\n    errorFormat: \"minimal\",\n  });\n} else {\n  globalThis[\"prisma\"] =\n    globalThis[\"prisma\"] ||\n    new PrismaClient({\n      errorFormat: \"pretty\",\n    });\n  prisma = globalThis[\"prisma\"];\n}\n\nexport default prisma;\n"
  },
  {
    "path": "db/schema.prisma",
    "content": "// This is your Prisma schema file,\n// learn more about it in the docs: https://pris.ly/d/prisma-schema\n\ndatasource db {\n    provider             = \"mysql\"\n    url                  = env(\"DATABASE_URL\")\n    referentialIntegrity = \"prisma\"\n}\n\ngenerator client {\n    provider        = \"prisma-client-js\"\n    previewFeatures = [\"referentialIntegrity\"]\n}\n\nmodel Account {\n    id                       String   @id @default(cuid())\n    createdAt                DateTime @default(now())\n    updatedAt                DateTime @updatedAt\n    userId                   String\n    type                     String\n    provider                 String\n    providerAccountId        String\n    refresh_token            String? @db.VarChar(500)\n    access_token             String? @db.VarChar(500)\n    refresh_token_expires_in Int?\n    expires_at               Int?\n    token_type               String?\n    scope                    String?\n    id_token                 String? @db.Text\n    session_state            String?\n    oauth_token_secret       String?\n    oauth_token              String?\n\n    user User @relation(fields: [userId], references: [id], onDelete: Cascade)\n\n    @@unique([provider, providerAccountId])\n}\n\nmodel Session {\n    id           String   @id @default(cuid())\n    sessionToken String   @unique\n    expires      DateTime\n    user         User?    @relation(fields: [userId], references: [id], onDelete: Cascade)\n    userId       String?\n}\n\nmodel User {\n    id            String    @id @default(cuid())\n    createdAt     DateTime  @default(now())\n    updatedAt     DateTime  @updatedAt\n    name          String?\n    email         String?   @unique\n    password      String?\n    emailVerified DateTime?\n    image         String?\n    role          String?   @default(\"user\")\n    accounts      Account[]\n    sessions      Session[]\n}\n\nmodel VerificationToken {\n    identifier String\n    token      String   @unique\n    expires    DateTime\n\n    @@unique([identifier, token])\n}\n"
  },
  {
    "path": "db/seed.ts",
    "content": "import { PrismaClient } from \"@prisma/client\";\nimport { hash } from \"bcryptjs\";\nconst prisma = new PrismaClient();\n\nasync function main() {\n  const encryptedPassword = await hash(\"password1234\", 12);\n  await prisma.user.upsert({\n    where: { email: \"a@a.com\" },\n    update: {},\n    create: {\n      email: \"a@a.com\",\n      name: \"Alice\",\n      password: encryptedPassword,\n    },\n  });\n\n  await prisma.user.upsert({\n    where: { email: \"b@b.com\" },\n    update: {},\n    create: {\n      email: \"b@b.com\",\n      name: \"Bob\",\n      password: encryptedPassword,\n    },\n  });\n\n  await prisma.user.upsert({\n    where: { email: \"c@c.com\" },\n    update: {},\n    create: {\n      email: \"c@c.com\",\n      name: \"Carla\",\n      password: encryptedPassword,\n    },\n  });\n}\n\nmain()\n  .catch((e) => {\n    console.error(e);\n    process.exit(1);\n  })\n  .finally(async () => {\n    await prisma.$disconnect();\n  });\n"
  },
  {
    "path": "lib/auth/WithAuth.tsx",
    "content": "import { useSession, signIn } from \"next-auth/react\";\nimport { useEffect } from \"react\";\nimport router from \"next/router\";\nimport Loader from \"@lib/components/Loader\";\n\nfunction WithAuth({ children, options }) {\n  const { data: session, status } = useSession();\n  const isUser = !!session?.user;\n  useEffect(() => {\n    // Do nothing while loading\n    if (status === \"loading\") {\n      return;\n    }\n\n    // If not authenticated, redirect to provided url or\n    if (!isUser) {\n      if (options?.redirectTo) {\n        router.push(options.redirectTo);\n      } else {\n        signIn();\n      }\n    }\n  }, [isUser, status]);\n\n  if (isUser) {\n    return children;\n  }\n\n  // Session is being fetched, or no user.\n  // If no user, useEffect() will redirect.\n  return (\n    <div className=\"h-screen w-screen flex flex-col justify-center content-center items-center\">\n      <Loader className=\"h-6 w-6\" />\n    </div>\n  );\n}\n\nexport default WithAuth;\n"
  },
  {
    "path": "lib/auth/passwords.ts",
    "content": "import { hash, compare } from 'bcryptjs';\n\nexport async function hashPassword(password) {\n    const hashedPassword = await hash(password, 12);\n    return hashedPassword;\n}\n\nexport async function verifyPassword(password, hashedPassword) {\n    const isValid = await compare(password, hashedPassword);\n    return isValid;\n}"
  },
  {
    "path": "lib/auth/session.ts",
    "content": "import { DefaultSession } from \"next-auth\";\nimport {\n  getSession as getNextSession,\n  GetSessionParams,\n} from \"next-auth/react\";\n\ntype DefaultSessionUser = NonNullable<DefaultSession[\"user\"]>;\n\ntype SessionUser = DefaultSessionUser & {\n  id: string;\n  role: string;\n};\n\nexport type Session = DefaultSession & {\n  user?: SessionUser;\n};\n\nexport async function getSession(\n  options: GetSessionParams\n): Promise<Session | null> {\n  const session = await getNextSession(options);\n\n  // that these are equal are ensured in `[...nextauth]`'s callback\n  return session as Session | null;\n}\n"
  },
  {
    "path": "lib/auth/useAuth.ts",
    "content": ""
  },
  {
    "path": "lib/components/Layouts/AdminLayout.tsx",
    "content": "import { signOut } from \"next-auth/react\";\nimport { Fragment } from \"react\";\nimport { Menu, Transition } from \"@headlessui/react\";\nimport { UserIcon } from \"@heroicons/react/outline\";\nimport { ChevronDownIcon } from \"@heroicons/react/solid\";\nimport classNames from \"classnames\";\nimport Link from \"next/link\";\n\nconst navigation = [\n  { name: \"Users\", href: \"#\", current: true },\n  { name: \"Help\", href: \"#\", current: false },\n];\n\nconst AdminLayout = (props) => {\n  return (\n    <>\n      <div className=\"min-h-full\">\n        <div className=\"flex flex-col flex-1\">\n          <div className=\"border-b\">\n            <div className=\"relative flex-shrink-0 flex h-16 bg-white\">\n              <div className=\"flex-1 px-4 flex justify-between sm:px-6 lg:max-w-6xl lg:mx-auto lg:px-8\">\n                <button\n                  type=\"button\"\n                  className=\"px-4 text-gray-400 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500 \"\n                  onClick={() => true}\n                >\n                  <img\n                    className=\"h-8 w-8 mx-auto\"\n                    src=\"/assets/planet-scale.svg\"\n                    alt=\"PlanetScale Logo\"\n                  />\n                </button>\n                <div className=\"flex-1 flex\"></div>\n                <div className=\"ml-4 flex items-center md:ml-6\">\n                  {/* Profile dropdown */}\n                  <Menu as=\"div\" className=\"ml-3 relative\">\n                    <div>\n                      <Menu.Button className=\"max-w-xs bg-gray-100 rounded-full flex items-center text-sm focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 p-2 lg:rounded-md lg:hover:bg-gray-50\">\n                        <UserIcon className=\"h-6 w-6 rounded-full\" />\n                        <span className=\"hidden  text-gray-700 text-sm font-medium lg:block\">\n                          <span className=\"sr-only\">Open user menu for </span>\n                          {/* {user.name ?? user.email} */}\n                        </span>\n                        <ChevronDownIcon\n                          className=\"flex-shrink-0 h-5 w-5 text-gray-400\"\n                          aria-hidden=\"true\"\n                        />\n                      </Menu.Button>\n                    </div>\n                    <Transition\n                      as={Fragment}\n                      enter=\"transition ease-out duration-100\"\n                      enterFrom=\"transform opacity-0 scale-95\"\n                      enterTo=\"transform opacity-100 scale-100\"\n                      leave=\"transition ease-in duration-75\"\n                      leaveFrom=\"transform opacity-100 scale-100\"\n                      leaveTo=\"transform opacity-0 scale-95\"\n                    >\n                      <Menu.Items className=\"origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg py-1 bg-white ring-1 ring-black ring-opacity-5 focus:outline-none z-10\">\n                        <Menu.Item>\n                          {({ active }) => (\n                            <a\n                              onClick={() => signOut()}\n                              className={classNames(\n                                active ? \"bg-gray-100\" : \"\",\n                                \"block px-4 py-2 text-sm text-gray-700\"\n                              )}\n                            >\n                              Logout\n                            </a>\n                          )}\n                        </Menu.Item>\n                      </Menu.Items>\n                    </Transition>\n                  </Menu>\n                </div>\n              </div>\n            </div>\n            <div className=\"relative flex-shrink-0 flex h-16 bg-white\">\n              <div className=\"flex-1 px-4 flex justify-between sm:px-6 lg:max-w-6xl lg:mx-auto lg:px-8\">\n                <div className=\"flex flex-1 \">\n                  {navigation.map((item) => (\n                    <Link key={item.name} href={item.href}>\n                      <a\n                        className={classNames(\n                          item.current\n                            ? \"border-b text-black\"\n                            : \" hover:border-b  hover:border-gray-200 text-gray-600 \",\n                          \"group flex items-center px-2 py-2 text-sm leading-6 font-medium\"\n                        )}\n                        aria-current={item.current ? \"page\" : undefined}\n                      >\n                        {item.name}\n                      </a>\n                    </Link>\n                  ))}\n                </div>\n              </div>\n            </div>\n          </div>\n          <main className=\"flex-1 pb-8\">\n            <div className=\"bg-white \">\n              <div className=\"px-4 sm:px-6 lg:max-w-6xl lg:mx-auto lg:px-8\">\n                <div className=\"pt-6 pb-2 md:flex md:items-center md:justify-between\">\n                  <div className=\"flex-1 min-w-0\">\n                    <div className=\"flex items-center\">\n                      <div>\n                        <div className=\"flex items-center\">\n                          <h1 className=\"text-xl font-bold leading-7 text-gray-900 sm:leading-9 sm:truncate\">\n                            {props.title}\n                          </h1>\n                        </div>\n                      </div>\n                    </div>\n                  </div>\n                </div>\n              </div>\n            </div>\n\n            <div className=\"mt-2\">{props.children}</div>\n          </main>\n        </div>\n      </div>\n    </>\n  );\n};\n\nexport default AdminLayout;\n"
  },
  {
    "path": "lib/components/Layouts/AppLayout.tsx",
    "content": "import classNames from \"classnames\";\nimport { useSession, signOut, signIn } from \"next-auth/react\";\nimport Link from \"next/link\";\nimport { Menu, Transition } from \"@headlessui/react\";\nimport { UserIcon } from \"@heroicons/react/outline\";\nimport { ChevronDownIcon } from \"@heroicons/react/solid\";\nimport { Fragment } from \"react\";\nimport { useRouter } from \"next/router\";\n\nconst AppLayout = (props) => {\n  const { status, data: session } = useSession({\n    required: false,\n  });\n\n  const router = useRouter();\n\n  const currentPath = router.pathname;\n  const NAV_ITEMS = [\n    {\n      title: \"Home\",\n      href: \"/\",\n    },\n    {\n      title: \"Client\",\n      href: \"/client\",\n    },\n    {\n      title: \"Server\",\n      href: \"/server\",\n    },\n    {\n      title: \"With Session\",\n      href: \"/with-session\",\n    },\n    {\n      title: \"Client Redirect\",\n      href: \"/client-redirect\",\n    },\n    {\n      title: \"Server Redirect\",\n      href: \"/server-redirect\",\n    },\n  ];\n\n  return (\n    <>\n      <div className=\"min-h-screen\">\n        <div className=\"flex flex-col flex-1\">\n          <div className=\"border-b\">\n            <div className=\"relative flex-shrink-0 flex h-16 bg-white\">\n              <div className=\"flex-1 px-4 flex justify-between sm:px-6 lg:max-w-6xl lg:mx-auto lg:px-8\">\n                <button\n                  type=\"button\"\n                  className=\"px-4 text-gray-400 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500 \"\n                >\n                  <img\n                    className=\"h-8 w-8 mx-auto\"\n                    src=\"/assets/planet-scale.svg\"\n                    alt=\"PlanetScale Logo\"\n                  />\n                </button>\n                <div className=\"flex-1 flex\"></div>\n                <div className=\"ml-4 flex items-center md:ml-6\">\n                  <Menu as=\"div\" className=\"ml-3 relative\">\n                    <div>\n                      <Menu.Button className=\"max-w-xs bg-gray-100 rounded-full flex items-center text-sm focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 p-2 lg:rounded-md lg:hover:bg-gray-50\">\n                        {session?.user?.image ? (\n                          <img\n                            className=\"h-6 w-6 rounded-full\"\n                            src={session.user.image}\n                            alt=\"PlanetScale Logo\"\n                          />\n                        ) : (\n                          <UserIcon className=\"h-6 w-6 rounded-full\" />\n                        )}\n\n                        <span className=\"hidden  text-gray-700 text-sm font-medium lg:block\">\n                          <span className=\"sr-only\">Open user menu for </span>\n                        </span>\n                        <ChevronDownIcon\n                          className=\"flex-shrink-0 h-5 w-5 text-gray-400\"\n                          aria-hidden=\"true\"\n                        />\n                      </Menu.Button>\n                    </div>\n                    <Transition\n                      as={Fragment}\n                      enter=\"transition ease-out duration-100\"\n                      enterFrom=\"transform opacity-0 scale-95\"\n                      enterTo=\"transform opacity-100 scale-100\"\n                      leave=\"transition ease-in duration-75\"\n                      leaveFrom=\"transform opacity-100 scale-100\"\n                      leaveTo=\"transform opacity-0 scale-95\"\n                    >\n                      <Menu.Items className=\"origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg py-1 bg-white ring-1 ring-black ring-opacity-5 focus:outline-none z-10\">\n                        {status == \"authenticated\" ? (\n                          <Menu.Item>\n                            {({ active }) => (\n                              <a\n                                onClick={() => signOut()}\n                                className={classNames(\n                                  active ? \"bg-gray-100\" : \"\",\n                                  \"block px-4 py-2 text-sm text-gray-700\"\n                                )}\n                              >\n                                Sign Out\n                              </a>\n                            )}\n                          </Menu.Item>\n                        ) : (\n                          <Menu.Item>\n                            {({ active }) => (\n                              <a\n                                onClick={() => signIn()}\n                                className={classNames(\n                                  active ? \"bg-gray-100\" : \"\",\n                                  \"block px-4 py-2 text-sm text-gray-700\"\n                                )}\n                              >\n                                Sign In\n                              </a>\n                            )}\n                          </Menu.Item>\n                        )}\n                      </Menu.Items>\n                    </Transition>\n                  </Menu>\n                </div>\n              </div>\n            </div>\n            <div className=\"relative flex-shrink-0 flex h-16 bg-white\">\n              <div className=\"flex-1 px-4 flex justify-between sm:px-6 lg:max-w-6xl lg:mx-auto lg:px-8\">\n                <div className=\"flex flex-1 \">\n                  {NAV_ITEMS.map((item) => (\n                    <Link key={item.title} href={item.href}>\n                      <a\n                        className={classNames(\n                          item.href === currentPath\n                            ? \"border-b border-indigo-600 text-black\"\n                            : \" hover:border-b  hover:border-gray-200 text-gray-600 \",\n                          \"group flex items-center px-2 py-2 text-sm leading-6 font-medium\"\n                        )}\n                        aria-current={\n                          item.href === currentPath ? \"page\" : undefined\n                        }\n                      >\n                        {item.title}\n                      </a>\n                    </Link>\n                  ))}\n                </div>\n              </div>\n            </div>\n          </div>\n          <main className=\"flex-1 pb-8\">\n            <div className=\"bg-white \">\n              <div className=\"px-4 sm:px-6 lg:max-w-6xl lg:mx-auto lg:px-8\">\n                <div className=\"pt-6 pb-2 md:flex md:items-center md:justify-between\">\n                  <div className=\"flex-1 min-w-0\">\n                    <div className=\"flex items-center\">\n                      <div>\n                        <div className=\"flex items-center\">\n                          <h1 className=\"text-xl font-bold leading-7 text-gray-900 sm:leading-9 sm:truncate\">\n                            {props.title}\n                          </h1>\n                        </div>\n                      </div>\n                    </div>\n                  </div>\n                </div>\n              </div>\n            </div>\n\n            <div className=\"mt-2\">\n              <div className=\"max-w-6xl mx-auto px-4 sm:px-6 lg:px-8\">\n                {props.children}\n              </div>\n            </div>\n          </main>\n        </div>\n      </div>\n    </>\n  );\n};\n\nexport default AppLayout;\n"
  },
  {
    "path": "lib/components/Loader.tsx",
    "content": "import classNames from \"classnames\";\n\ntype LoaderProps = {\n  className?: string;\n  absoluteFill?: string;\n};\nconst Loader = ({ className, absoluteFill }: LoaderProps) => {\n  return (\n    <div\n      className={classNames(\n        absoluteFill &&\n          \"absolute w-full h-full flex flex-col justify-center content-center items-center\"\n      )}\n    >\n      <img\n        className={classNames(\"absolute w-6 h-6\", className)}\n        src=\"/assets/loading.svg\"\n      />\n    </div>\n  );\n};\n\nexport default Loader;\n"
  },
  {
    "path": "lib/components/NavigationBar.tsx",
    "content": "/*\n  This example requires Tailwind CSS v2.0+ \n  \n  This example requires some changes to your config:\n  \n  ```\n  // tailwind.config.js\n  module.exports = {\n    // ...\n    plugins: [\n      // ...\n      require('@tailwindcss/forms'),\n    ],\n  }\n  ```\n*/\nimport { Fragment } from \"react\";\nimport { Disclosure, Menu, Transition } from \"@headlessui/react\";\nimport { SearchIcon } from \"@heroicons/react/solid\";\nimport { BellIcon, MenuIcon, XIcon } from \"@heroicons/react/outline\";\n\nfunction classNames(...classes) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nexport default function NavigationBar() {\n  return (\n    <Disclosure as=\"nav\" className=\"bg-white shadow\">\n      {({ open }) => (\n        <>\n          <div className=\"max-w-7xl mx-auto px-2 sm:px-4 lg:px-8\">\n            <div className=\"flex justify-between h-16\">\n              <div className=\"flex px-2 lg:px-0\">\n                <div className=\"flex-shrink-0 flex items-center\">\n                  <img\n                    className=\"block h-8 w-auto\"\n                    src=\"/assets/planet-scale.svg\"\n                    alt=\"Workflow\"\n                  />\n                </div>\n                <div className=\"hidden lg:ml-6 lg:flex lg:space-x-8\">\n                  {/* Current: \"border-indigo-500 text-gray-900\", Default: \"border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700\" */}\n                  <a\n                    href=\"#\"\n                    className=\"border-indigo-500 text-gray-900 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium\"\n                  >\n                    Dashboard\n                  </a>\n                  <a\n                    href=\"#\"\n                    className=\"border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium\"\n                  >\n                    Team\n                  </a>\n                  <a\n                    href=\"#\"\n                    className=\"border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium\"\n                  >\n                    Projects\n                  </a>\n                  <a\n                    href=\"#\"\n                    className=\"border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium\"\n                  >\n                    Calendar\n                  </a>\n                </div>\n              </div>\n              <div className=\"flex items-center lg:hidden\">\n                {/* Mobile menu button */}\n                <Disclosure.Button className=\"inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500\">\n                  <span className=\"sr-only\">Open main menu</span>\n                  {open ? (\n                    <XIcon className=\"block h-6 w-6\" aria-hidden=\"true\" />\n                  ) : (\n                    <MenuIcon className=\"block h-6 w-6\" aria-hidden=\"true\" />\n                  )}\n                </Disclosure.Button>\n              </div>\n              <div className=\"hidden lg:ml-4 lg:flex lg:items-center\">\n                {/* Profile dropdown */}\n                <Menu as=\"div\" className=\"ml-4 relative flex-shrink-0\">\n                  <div>\n                    <Menu.Button className=\"bg-white rounded-full flex text-sm focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500\">\n                      <span className=\"sr-only\">Open user menu</span>\n                      <img\n                        className=\"h-8 w-8 rounded-full\"\n                        src=\"https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80\"\n                        alt=\"\"\n                      />\n                    </Menu.Button>\n                  </div>\n                  <Transition\n                    as={Fragment}\n                    enter=\"transition ease-out duration-100\"\n                    enterFrom=\"transform opacity-0 scale-95\"\n                    enterTo=\"transform opacity-100 scale-100\"\n                    leave=\"transition ease-in duration-75\"\n                    leaveFrom=\"transform opacity-100 scale-100\"\n                    leaveTo=\"transform opacity-0 scale-95\"\n                  >\n                    <Menu.Items className=\"origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg py-1 bg-white ring-1 ring-black ring-opacity-5 focus:outline-none\">\n                      <Menu.Item>\n                        {({ active }) => (\n                          <a\n                            href=\"#\"\n                            className={classNames(\n                              active ? \"bg-gray-100\" : \"\",\n                              \"block px-4 py-2 text-sm text-gray-700\"\n                            )}\n                          >\n                            Your Profile\n                          </a>\n                        )}\n                      </Menu.Item>\n                      <Menu.Item>\n                        {({ active }) => (\n                          <a\n                            href=\"#\"\n                            className={classNames(\n                              active ? \"bg-gray-100\" : \"\",\n                              \"block px-4 py-2 text-sm text-gray-700\"\n                            )}\n                          >\n                            Settings\n                          </a>\n                        )}\n                      </Menu.Item>\n                      <Menu.Item>\n                        {({ active }) => (\n                          <a\n                            href=\"#\"\n                            className={classNames(\n                              active ? \"bg-gray-100\" : \"\",\n                              \"block px-4 py-2 text-sm text-gray-700\"\n                            )}\n                          >\n                            Sign out\n                          </a>\n                        )}\n                      </Menu.Item>\n                    </Menu.Items>\n                  </Transition>\n                </Menu>\n              </div>\n            </div>\n          </div>\n\n          <Disclosure.Panel className=\"lg:hidden\">\n            <div className=\"pt-2 pb-3 space-y-1\">\n              {/* Current: \"bg-indigo-50 border-indigo-500 text-indigo-700\", Default: \"border-transparent text-gray-600 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-800\" */}\n              <Disclosure.Button\n                as=\"a\"\n                href=\"#\"\n                className=\"bg-indigo-50 border-indigo-500 text-indigo-700 block pl-3 pr-4 py-2 border-l-4 text-base font-medium\"\n              >\n                Dashboard\n              </Disclosure.Button>\n              <Disclosure.Button\n                as=\"a\"\n                href=\"#\"\n                className=\"border-transparent text-gray-600 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-800 block pl-3 pr-4 py-2 border-l-4 text-base font-medium\"\n              >\n                Team\n              </Disclosure.Button>\n              <Disclosure.Button\n                as=\"a\"\n                href=\"#\"\n                className=\"border-transparent text-gray-600 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-800 block pl-3 pr-4 py-2 border-l-4 text-base font-medium\"\n              >\n                Projects\n              </Disclosure.Button>\n              <Disclosure.Button\n                as=\"a\"\n                href=\"#\"\n                className=\"border-transparent text-gray-600 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-800 block pl-3 pr-4 py-2 border-l-4 text-base font-medium\"\n              >\n                Calendar\n              </Disclosure.Button>\n            </div>\n            <div className=\"pt-4 pb-3 border-t border-gray-200\">\n              <div className=\"flex items-center px-4\">\n                <div className=\"flex-shrink-0\">\n                  <img\n                    className=\"h-10 w-10 rounded-full\"\n                    src=\"https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80\"\n                    alt=\"\"\n                  />\n                </div>\n                <div className=\"ml-3\">\n                  <div className=\"text-base font-medium text-gray-800\">\n                    Tom Cook\n                  </div>\n                  <div className=\"text-sm font-medium text-gray-500\">\n                    tom@example.com\n                  </div>\n                </div>\n                <button\n                  type=\"button\"\n                  className=\"ml-auto flex-shrink-0 bg-white p-1 text-gray-400 rounded-full hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500\"\n                >\n                  <span className=\"sr-only\">View notifications</span>\n                  <BellIcon className=\"h-6 w-6\" aria-hidden=\"true\" />\n                </button>\n              </div>\n              <div className=\"mt-3 space-y-1\">\n                <Disclosure.Button\n                  as=\"a\"\n                  href=\"#\"\n                  className=\"block px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100\"\n                >\n                  Your Profile\n                </Disclosure.Button>\n                <Disclosure.Button\n                  as=\"a\"\n                  href=\"#\"\n                  className=\"block px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100\"\n                >\n                  Settings\n                </Disclosure.Button>\n                <Disclosure.Button\n                  as=\"a\"\n                  href=\"#\"\n                  className=\"block px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100\"\n                >\n                  Sign out\n                </Disclosure.Button>\n              </div>\n            </div>\n          </Disclosure.Panel>\n        </>\n      )}\n    </Disclosure>\n  );\n}\n"
  },
  {
    "path": "lib/styles/index.css",
    "content": "/* purgecss start ignore */\n@tailwind base;\n@tailwind components;\n/* purgecss end ignore */\n\n@tailwind utilities;\n\n/* body {\n  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif,\n    Apple Color Emoji, Segoe UI Emoji;\n} */\n\n.button {\n  @apply inline-flex px-2.5 py-1.5 text-xs text-center items-center justify-center border border-transparent font-medium shadow-sm text-white bg-black focus:outline-none focus:ring-1 focus:ring-offset-0 focus:ring-gray-800;\n  @apply disabled:bg-opacity-80;\n  @apply rounded-md;\n}\n\n.button__round {\n  @apply rounded-full !important;\n}\n\n.button__secondary {\n  @apply bg-white text-black;\n  @apply border border-gray-400;\n}\n\n.button__third {\n  @apply bg-black text-white;\n}\n\n.button__sm {\n  @apply px-2.5 py-1.5 text-xs;\n}\n\n.button__md {\n  @apply px-3 py-2 text-sm;\n}\n\n.button__lg {\n  @apply px-4 py-2 text-sm;\n}\n\n.button__xl {\n  @apply px-6 py-3 text-base;\n}\n\nblockquote {\n  @apply bg-gray-200;\n  @apply my-6 p-2;\n  @apply overflow-auto break-words;\n}\n\na {\n  @apply text-blue-300;\n}"
  },
  {
    "path": "lib/types.ts",
    "content": "import { AppProps } from \"next/app\";\nimport { Component } from \"react\";\n\nexport type AuthenticatedPage = {\n  role?: string;\n  redirectTo?: string; // redirect to this url\n};\nexport type ExtendedPageProps = {\n  requiresAuth?: boolean\n  auth?: AuthenticatedPage;\n  layout?: Component;\n};\n\nexport type ExtendedAppProps = AppProps & {\n  Component: ExtendedPageProps;\n};\n"
  },
  {
    "path": "netlify.toml",
    "content": "[build]\ncommand = \"yarn db:generate && yarn build\"\npublish = \".next\"\n\n[[plugins]]\npackage = \"@netlify/plugin-nextjs\"\n\n[template.environment]\nNEXTAUTH_SECRET = \"Secret, use https://generate-secret.now.sh/32 to create one.\"\nDATABASE_URL = \"Database URL, leave blank for now. See docs for more info.\"\nNEXTAUTH_URL = \"NextAuth URL, leave blank for now. See docs for more info.\"\n"
  },
  {
    "path": "next-env.d.ts",
    "content": "/// <reference types=\"next\" />\n/// <reference types=\"next/types/global\" />\n/// <reference types=\"next/image-types/global\" />\n\n// NOTE: This file should not be edited\n// see https://nextjs.org/docs/basic-features/typescript for more information.\n"
  },
  {
    "path": "next.config.js",
    "content": "if (!process.env.NEXTAUTH_URL) {\n  console.warn(\n    \"\\x1b[33mwarn\",\n    \"\\x1b[0m\",\n    \"NEXTAUTH_URL environment variable is not set.\"\n  );\n  if (process.env.URL) {\n    process.env.NEXTAUTH_URL = process.env.URL;\n    console.warn(\n      \"\\x1b[33mwarn\",\n      \"\\x1b[0m\",\n      `NEXTAUTH_URL environment variable is not set. Using Netlify URL ${process.env.URL}.`\n    );\n  }\n}\n\nmodule.exports = {\n  target: \"experimental-serverless-trace\",\n  future: {\n    webpack5: true,\n  },\n  typescript: {\n    ignoreBuildErrors: true,\n  },\n};\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"starter\",\n  \"version\": \"0.0.0\",\n  \"private\": true,\n  \"scripts\": {\n    \"dev\": \"next\",\n    \"build\": \"next build\",\n    \"start\": \"next start\",\n    \"db:generate\": \"prisma generate --schema=./db/schema.prisma\",\n    \"db:migrate\": \"prisma migrate dev --schema=./db/schema.prisma --skip-seed\",\n    \"db:reset\": \"prisma migrate reset --schema=./db/schema.prisma --skip-seed\",\n    \"db:push\": \"prisma db push --schema=./db/schema.prisma --skip-seed\",\n    \"db:seed\": \"npx prisma db seed\",\n    \"db:studio\": \"prisma studio --schema=./db/schema.prisma\",\n    \"now-build\": \"yarn generate --schema=./db/schema.prisma && next build\"\n  },\n  \"dependencies\": {\n    \"@headlessui/react\": \"^1.4.1\",\n    \"@heroicons/react\": \"^1.0.5\",\n    \"@next-auth/prisma-adapter\": \"^0.5.2-next.19\",\n    \"@prisma/client\": \"^3.3.0\",\n    \"@tailwindcss/forms\": \"^0.2.1\",\n    \"bcryptjs\": \"^2.4.3\",\n    \"classnames\": \"^2.3.1\",\n    \"lodash\": \"^4.17.21\",\n    \"next\": \"^12.0.5\",\n    \"next-auth\": \"4.0.0-beta.6\",\n    \"next-connect\": \"^0.10.2\",\n    \"react\": \"^17.0.2\",\n    \"react-dom\": \"^17.0.2\",\n    \"react-hook-form\": \"^7.18.1\",\n    \"react-query\": \"^3.23.2\",\n    \"superagent\": \"^6.1.0\"\n  },\n  \"prisma\": {\n    \"seed\": \"ts-node --compiler-options {\\\"module\\\":\\\"CommonJS\\\"} db/seed.ts\"\n  },\n  \"devDependencies\": {\n    \"@netlify/plugin-nextjs\": \"^4.0.0-beta.4\",\n    \"@types/bcryptjs\": \"^2.4.2\",\n    \"@types/lodash\": \"^4.14.176\",\n    \"@types/node\": \"^14.14.33\",\n    \"@types/react\": \"^17.0.3\",\n    \"@types/superagent\": \"^4.1.13\",\n    \"@typescript-eslint/eslint-plugin\": \"^4.27.0\",\n    \"@typescript-eslint/parser\": \"^4.27.0\",\n    \"autoprefixer\": \"^10.2.5\",\n    \"eslint\": \"^7.29.0\",\n    \"eslint-config-prettier\": \"^8.3.0\",\n    \"eslint-plugin-prettier\": \"^3.4.0\",\n    \"eslint-plugin-react\": \"^7.24.0\",\n    \"eslint-plugin-react-hooks\": \"^4.2.0\",\n    \"jest\": \"^27.0.5\",\n    \"lint-staged\": \"^11.0.0\",\n    \"mockdate\": \"^3.0.5\",\n    \"postcss\": \"^8.2.8\",\n    \"prettier\": \"^2.3.1\",\n    \"prisma\": \"^3.3.0\",\n    \"tailwindcss\": \"^2.2.2\",\n    \"ts-node\": \"^10.4.0\",\n    \"typescript\": \"^4.2.3\",\n    \"webpack\": \"^5.62.1\"\n  }\n}\n"
  },
  {
    "path": "pages/_app.tsx",
    "content": "import React from \"react\";\nimport type { ExtendedAppProps } from \"@lib/types\";\nimport { QueryClient, QueryClientProvider } from \"react-query\";\nimport { SessionProvider } from \"next-auth/react\";\n\nimport \"@lib/styles/index.css\";\nimport WithAuth from \"@lib/auth/WithAuth\";\n\nexport const queryClient = new QueryClient();\n\nfunction MyApp({\n  Component,\n  pageProps: { session, ...pageProps },\n}: ExtendedAppProps) {\n  return (\n    <SessionProvider session={session} refetchInterval={5 * 60}>\n      <QueryClientProvider client={queryClient}>\n        {Component.auth ? (\n          <WithAuth options={Component.auth}>\n            <Component {...pageProps} />\n          </WithAuth>\n        ) : (\n          <Component {...pageProps} />\n        )}\n      </QueryClientProvider>\n    </SessionProvider>\n  );\n}\n\nexport default MyApp;\n"
  },
  {
    "path": "pages/admin/index.tsx",
    "content": "import { useQuery } from \"react-query\";\nimport { useSession } from \"next-auth/react\";\nimport { useRouter } from \"next/router\";\nimport { ChevronRightIcon } from \"@heroicons/react/solid\";\nimport { GetServerSidePropsContext } from \"next\";\nimport classNames from \"classnames\";\nimport AdminLayout from \"@lib/components/Layouts/AdminLayout\";\nimport { getSession } from \"@lib/auth/session\";\nimport superagent from \"superagent\";\n\nconst statusStyles = {\n  true: \"bg-green-100 text-green-800\",\n  false: \"bg-gray-100 text-gray-800\",\n};\n\nfunction Page() {\n  const router = useRouter();\n  const {\n    status,\n    data: { session },\n  } = useSession({\n    required: true,\n    onUnauthenticated() {\n      router.push(\"/\", \"/\", {});\n    },\n  });\n\n  if (status === \"loading\") {\n    return \"Loading or not authenticated...\";\n  }\n\n  const usersQuery = useQuery([\"users\"], async () => {\n    const data = await superagent.get(\"/api/users\").send({\n      select: {\n        id: true,\n        name: true,\n        email: true,\n        image: true,\n        emailVerified: true,\n        accounts: {\n          select: {\n            type: true,\n            provider: true,\n          },\n        },\n      },\n    });\n\n    return data.body;\n  });\n\n  if (usersQuery.isLoading) {\n    return <div>loading...</div>;\n  }\n\n  return (\n    <>\n      <AdminLayout title=\"Users\">\n        {/* {/* Activity list (smallest breakpoint only) */}\n        <div className=\" sm:hidden\">\n          <ul\n            role=\"list\"\n            className=\"mt-2 divide-y divide-gray-200 overflow-hidden  sm:hidden\"\n          >\n            {usersQuery?.data &&\n              usersQuery.data.map((user) => {\n                return (\n                  <li key={user.email}>\n                    <a className=\"block px-4 py-4 bg-white hover:bg-gray-50\">\n                      <span className=\"flex items-center space-x-4\">\n                        <span className=\"flex-1 flex space-x-2 truncate\">\n                          <span className=\"flex flex-col text-gray-500 text-sm truncate\">\n                            <span className=\"truncate\">{user.email}</span>\n                            <span>{user.name}</span>\n                            <span\n                              className={classNames(\n                                statusStyles[\n                                  user.emailVerified ? \"true\" : \"false\"\n                                ],\n                                \"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium capitalize\"\n                              )}\n                            >\n                              {user.emailVerified ? \"Verified\" : \"Not Verified\"}\n                            </span>\n                          </span>\n                        </span>\n                        <ChevronRightIcon\n                          className=\"flex-shrink-0 h-5 w-5 text-gray-400\"\n                          aria-hidden=\"true\"\n                        />\n                      </span>\n                    </a>\n                  </li>\n                );\n              })}\n          </ul>\n        </div>\n\n        {/* Activity table (small breakpoint and up) */}\n        <div className=\"hidden sm:block\">\n          <div className=\"max-w-6xl mx-auto px-4 sm:px-6 lg:px-8\">\n            <div className=\"flex flex-col mt-2\">\n              <div className=\"align-middle min-w-full overflow-x-auto overflow-hidden \">\n                <table className=\"min-w-full\">\n                  <thead className=\"border rounded-md\">\n                    <tr className=\"border rounded-md\">\n                      <th className=\"px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider\">\n                        Email\n                      </th>\n                      <th className=\"px-6 py-3 bg-gray-50 text-right text-xs font-medium text-gray-500 uppercase tracking-wider\">\n                        Name\n                      </th>\n                      <th className=\"hidden px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider md:block\">\n                        Status\n                      </th>\n                      <th className=\"px-6 py-3 bg-gray-50 text-right text-xs font-medium text-gray-500 uppercase tracking-wider\">\n                        Providers\n                      </th>\n                    </tr>\n                  </thead>\n                  <tbody className=\"bg-white \">\n                    {usersQuery?.data &&\n                      usersQuery.data.map((user) => {\n                        return (\n                          <tr key={user.email} className=\"bg-white\">\n                            <td className=\"px-6 py-4 whitespace-nowrap text-sm text-gray-900\">\n                              <div className=\"flex\">\n                                <a className=\"group inline-flex space-x-2 truncate text-sm\">\n                                  <p className=\"text-gray-500 truncate group-hover:text-gray-900\">\n                                    {user.email}\n                                  </p>\n                                </a>\n                              </div>\n                            </td>\n                            <td className=\"px-6 py-4 text-right whitespace-nowrap text-sm text-gray-500\">\n                              {user.name}\n                            </td>\n                            <td className=\"hidden px-6 py-4 whitespace-nowrap text-sm text-gray-500 md:block\">\n                              <span\n                                className={classNames(\n                                  statusStyles[\n                                    user.emailVerified ? \"true\" : \"false\"\n                                  ],\n                                  \"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium capitalize\"\n                                )}\n                              >\n                                {user.emailVerified\n                                  ? \"Verified\"\n                                  : \"Not Verified\"}\n                              </span>\n                            </td>\n                            <td className=\"px-6 py-4 text-right whitespace-nowrap text-sm text-gray-500\">\n                              {user?.accounts && user?.accounts?.length > 0 ? (\n                                user.accounts.map((account) => {\n                                  return <p>{account.provider}</p>;\n                                })\n                              ) : (\n                                <p>credentials</p>\n                              )}\n                            </td>\n                          </tr>\n                        );\n                      })}\n                  </tbody>\n                </table>\n              </div>\n            </div>\n          </div>\n        </div>\n      </AdminLayout>\n    </>\n  );\n}\n\n// Page.auth = true\n\nexport default Page;\n\nexport async function getServerSideProps(context: GetServerSidePropsContext) {\n  const session = await getSession(context);\n\n  if (!session || session?.user?.role !== \"admin\") {\n    return { redirect: { permanent: false, destination: \"/\" } };\n  }\n\n  return {\n    props: { session: session },\n  };\n}\n"
  },
  {
    "path": "pages/admin/setup.tsx",
    "content": "import { getCsrfToken, signIn } from \"next-auth/react\";\nimport { GetServerSidePropsContext } from \"next\";\nimport Head from \"next/head\";\nimport React from \"react\";\nimport { useForm } from \"react-hook-form\";\nimport superagent from \"superagent\";\n\nimport prisma from \"@db\";\n\nconst MINIMUM_ACTIVITY_TIMEOUT = 850;\ntype LoginFormValues = {\n  csrfToken: string;\n  email: string;\n  password: string;\n};\n\nexport default function Page({ csrfToken }) {\n  const [isSubmitting, setSubmitting] = React.useState(false);\n\n  const { register, handleSubmit } = useForm();\n\n  const createAdminAccountHandler = async (data: LoginFormValues) => {\n    const response = await superagent\n      .post(\"/api/auth/administrator/create\")\n      .send({\n        csrfToken: data.csrfToken,\n        email: data.email,\n        password: data.password,\n      });\n\n    return response.body;\n  };\n  const onSubmit = async (data: LoginFormValues) => {\n    setSubmitting(true);\n    try {\n      createAdminAccountHandler(data)\n        .then((response) => {\n          signIn(\"admin-login\", {\n            callbackUrl: \"/admin\",\n            email: data.email,\n            password: data.password,\n          });\n        })\n        .catch((error) => {});\n\n      setTimeout(() => {\n        setSubmitting(false);\n      }, MINIMUM_ACTIVITY_TIMEOUT);\n    } catch (error) {\n      console.error(error);\n      //   setError(error)\n      setSubmitting(false);\n    }\n  };\n\n  return (\n    <div className=\"min-h-screen  flex flex-col justify-center py-12 sm:px-6 lg:px-8\">\n      <Head>\n        <title>Setup</title>\n        <link rel=\"icon\" href=\"/favicon.ico\" />\n      </Head>\n      <div className=\"sm:mx-auto sm:w-full sm:max-w-md text-center py-12\">\n        <img\n          className=\"h-16 mx-auto\"\n          src=\"/assets/planet-scale.svg\"\n          alt=\"PlanetScale Logo\"\n        />\n      </div>\n      <div className=\" flex flex-col justify-center py-12 sm:px-6 lg:px-8 mt-8\">\n        <div className=\"sm:mx-auto sm:w-full sm:max-w-md text-center \">\n          <p>Welcome to the PlanetScale Next.js Starter App</p>\n          <p>Get started by creating an administrative account to setup.</p>\n        </div>\n        <div className=\"mt-8 sm:mx-auto sm:w-full sm:max-w-md\">\n          <div className=\"py-8 px-4 mx-2 rounded-sm sm:px-10\">\n            <form className=\" text-center \" onSubmit={handleSubmit(onSubmit)}>\n              <input\n                name=\"csrfToken\"\n                {...register(\"csrfToken\")}\n                type=\"hidden\"\n                defaultValue={csrfToken}\n                hidden\n              />\n              <div className=\"\">\n                <label\n                  htmlFor=\"email\"\n                  className=\"block text-sm font-medium text-neutral-400\"\n                >\n                  Email address\n                </label>\n                <div className=\"mt-1\">\n                  <input\n                    id=\"email\"\n                    name=\"email\"\n                    type=\"email\"\n                    autoComplete=\"email\"\n                    required\n                    {...register(\"email\")}\n                    className=\"appearance-none w-full font-medium py-3 border-b border-t-0 border-l-0 border-r-0 border-dashed outline-none text-xl text-center leading-6 bg-transparent placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 transition duration-150 ease-in-out\"\n                  />\n                </div>\n              </div>\n\n              <div>\n                <div className=\"mt-8\">\n                  <label\n                    htmlFor=\"password\"\n                    className=\"block text-sm font-medium text-neutral-400\"\n                  >\n                    Password\n                  </label>\n                </div>\n                <div className=\"mt-1\">\n                  <input\n                    id=\"password\"\n                    name=\"password\"\n                    type=\"password\"\n                    autoComplete=\"current-password\"\n                    minLength={12}\n                    required\n                    {...register(\"password\")}\n                    className=\"appearance-none w-full font-medium py-3 border-b border-t-0 border-l-0 border-r-0 border-dashed outline-none text-xl text-center leading-6 bg-transparent placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 transition duration-150 ease-in-out\"\n                  />\n                </div>\n              </div>\n\n              <div className=\"mt-16 space-y-2 flex justify-center\">\n                <button\n                  type=\"submit\"\n                  disabled={isSubmitting}\n                  className=\"button button__round button__md button__primary w-full\"\n                >\n                  {isSubmitting ? (\n                    <img src=\"/assets/loading.svg\" />\n                  ) : (\n                    <p>Create Account</p>\n                  )}\n                </button>\n              </div>\n            </form>\n          </div>\n        </div>\n      </div>\n    </div>\n  );\n}\n\nexport async function getServerSideProps(context: GetServerSidePropsContext) {\n  const maybeAdministrator = await prisma.user.findFirst({\n    where: {\n      role: \"admin\",\n    },\n  });\n\n  if (maybeAdministrator) {\n    return {\n      redirect: {\n        destination: \"/\",\n        permanent: false,\n      },\n    };\n  }\n  return {\n    props: { csrfToken: await getCsrfToken({ req: context.req }) },\n  };\n}\n"
  },
  {
    "path": "pages/admin/sign-in.tsx",
    "content": "import { getCsrfToken, getSession, signIn } from \"next-auth/react\";\nimport { GetServerSidePropsContext } from \"next\";\nimport Head from \"next/head\";\nimport React from \"react\";\nimport { useForm } from \"react-hook-form\";\n\nconst MINIMUM_ACTIVITY_TIMEOUT = 850;\ntype LoginFormValues = {\n  csrfToken: string;\n  email: string;\n  password: string;\n};\n\nexport default function Page({ csrfToken }) {\n  const [isSubmitting, setSubmitting] = React.useState(false);\n\n  const { register, handleSubmit } = useForm();\n\n  const onSubmit = async (data: LoginFormValues) => {\n    setSubmitting(true);\n    try {\n      signIn(\"admin-login\", {\n        callbackUrl: \"/admin\",\n        redirect: true,\n        email: data.email,\n        password: data.password,\n      });\n\n      setTimeout(() => {\n        setSubmitting(false);\n      }, MINIMUM_ACTIVITY_TIMEOUT);\n    } catch (error) {\n      console.error(error);\n      //   setError(error)\n      setSubmitting(false);\n    }\n  };\n\n  return (\n    <div className=\"min-h-screen  flex flex-col justify-center py-12 sm:px-6 lg:px-8\">\n      <Head>\n        <title>Admin Sign In</title>\n        <link rel=\"icon\" href=\"/favicon.ico\" />\n      </Head>\n      <div className=\"sm:mx-auto sm:w-full sm:max-w-md text-center py-12\">\n        <img\n          className=\"h-16 mx-auto\"\n          src=\"/assets/planet-scale.svg\"\n          alt=\"PlanetScale Logo\"\n        />\n      </div>\n      <div className=\" flex flex-col justify-center py-12 sm:px-6 lg:px-8 mt-8\">\n        <div className=\"sm:mx-auto sm:w-full sm:max-w-md text-center \">\n          <p>Admin Sign In</p>\n        </div>\n        <div className=\"mt-8 sm:mx-auto sm:w-full sm:max-w-md\">\n          <div className=\"py-8 px-4 mx-2 rounded-sm sm:px-10\">\n            <form className=\"text-center\" onSubmit={handleSubmit(onSubmit)}>\n              <input\n                name=\"csrfToken\"\n                {...register(\"csrfToken\")}\n                type=\"hidden\"\n                defaultValue={csrfToken}\n                hidden\n              />\n              <div className=\"\">\n                <label\n                  htmlFor=\"email\"\n                  className=\"block text-sm font-medium text-neutral-400\"\n                >\n                  Email address\n                </label>\n                <div className=\"mt-1\">\n                  <input\n                    id=\"email\"\n                    name=\"email\"\n                    type=\"email\"\n                    autoComplete=\"email\"\n                    required\n                    {...register(\"email\")}\n                    className=\"appearance-none w-full font-medium py-3 border-b border-t-0 border-l-0 border-r-0 border-dashed outline-none text-xl text-center leading-6 bg-transparent placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 transition duration-150 ease-in-out\"\n                  />\n                </div>\n              </div>\n\n              <div>\n                <div className=\"mt-8\">\n                  <label\n                    htmlFor=\"password\"\n                    className=\"block text-sm font-medium text-neutral-400\"\n                  >\n                    Password\n                  </label>\n                </div>\n                <div className=\"mt-1\">\n                  <input\n                    id=\"password\"\n                    name=\"password\"\n                    type=\"password\"\n                    autoComplete=\"current-password\"\n                    minLength={12}\n                    required\n                    {...register(\"password\")}\n                    className=\"appearance-none w-full font-medium py-3 border-b border-t-0 border-l-0 border-r-0 border-dashed outline-none text-xl text-center leading-6 bg-transparent placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 transition duration-150 ease-in-out\"\n                  />\n                </div>\n              </div>\n\n              <div className=\"mt-16 space-y-2 flex justify-center\">\n                <button\n                  type=\"submit\"\n                  disabled={isSubmitting}\n                  className=\"button button__round button__md button__primary w-full\"\n                >\n                  {isSubmitting ? (\n                    <img src=\"/assets/loading.svg\" />\n                  ) : (\n                    <p>Sign In</p>\n                  )}\n                </button>\n              </div>\n            </form>\n          </div>\n        </div>\n      </div>\n    </div>\n  );\n}\nexport async function getServerSideProps(context: GetServerSidePropsContext) {\n  const session = await getSession(context);\n\n  if (session) {\n    return { redirect: { permanent: false, destination: \"/\" } };\n  }\n\n  return {\n    props: { csrfToken: await getCsrfToken({ req: context.req }) },\n  };\n}\n"
  },
  {
    "path": "pages/api/auth/[...nextauth].ts",
    "content": "import NextAuth from \"next-auth\";\nimport CredentialsProvider from \"next-auth/providers/credentials\";\nimport GitHubProvider from \"next-auth/providers/github\";\nimport { PrismaAdapter } from \"@next-auth/prisma-adapter\";\n\nimport { verifyPassword, hashPassword } from \"@lib/auth/passwords\";\nimport { Session } from \"@lib/auth/session\";\nimport prisma from \"@db/index\";\n\nexport default NextAuth({\n  adapter: PrismaAdapter(prisma),\n  secret: process.env.NEXTAUTH_SECRET,\n  session: {\n    jwt: true,\n  },\n  pages: {\n    signIn: \"/sign-in\",\n    // signOut: \"/auth/logout\",\n    // error: \"/auth/error\", // Error code passed in query string as ?error=\n  },\n  providers: [\n    GitHubProvider({\n      clientId: process.env.GITHUB_CLIENT_ID,\n      clientSecret: process.env.GITHUB_CLIENT_SECRET,\n    }),\n    CredentialsProvider({\n      id: \"app-login\",\n      name: \"App Login\",\n      credentials: {\n        email: {\n          label: \"Email Address\",\n          type: \"email\",\n          placeholder: \"john.doe@example.com\",\n        },\n        password: {\n          label: \"Password\",\n          type: \"password\",\n          placeholder: \"Your super secure password\",\n        },\n      },\n      async authorize(credentials) {\n        try {\n          let maybeUser = await prisma.user.findFirst({\n            where: {\n              email: credentials.email,\n            },\n            select: {\n              id: true,\n              email: true,\n              password: true,\n              name: true,\n              role: true,\n            },\n          });\n\n          if (!maybeUser) {\n            if (!credentials.password || !credentials.email) {\n              throw new Error(\"Invalid Credentials\");\n            }\n\n            maybeUser = await prisma.user.create({\n              data: {\n                email: credentials.email,\n                password: await hashPassword(credentials.password),\n              },\n              select: {\n                id: true,\n                email: true,\n                password: true,\n                name: true,\n                role: true,\n              },\n            });\n          } else {\n            const isValid = await verifyPassword(\n              credentials.password,\n              maybeUser.password\n            );\n\n            if (!isValid) {\n              throw new Error(\"Invalid Credentials\");\n            }\n          }\n\n          return {\n            id: maybeUser.id,\n            email: maybeUser.email,\n            name: maybeUser.name,\n            role: maybeUser.role,\n          };\n        } catch (error) {\n          console.log(error);\n          throw error;\n        }\n      },\n    }),\n    CredentialsProvider({\n      id: \"admin-login\",\n      name: \"Administrator Login\",\n      credentials: {\n        email: {\n          label: \"Email Address\",\n          type: \"email\",\n          placeholder: \"john.doe@example.com\",\n        },\n        password: {\n          label: \"Password\",\n          type: \"password\",\n          placeholder: \"Your super secure password\",\n        },\n      },\n      async authorize(credentials) {\n        let maybeUser = await prisma.user.findFirst({\n          where: {\n            email: credentials.email,\n          },\n          select: {\n            id: true,\n            email: true,\n            password: true,\n            name: true,\n            role: true,\n          },\n        });\n\n        if (!maybeUser) {\n          throw new Error(\"Unauthorized.\");\n        }\n\n        if (maybeUser?.role !== \"admin\") {\n          throw new Error(\"Unauthorized.\");\n        }\n\n        const isValid = await verifyPassword(\n          credentials.password,\n          maybeUser.password\n        );\n\n        if (!isValid) {\n          throw new Error(\"Invalid Credentials\");\n        }\n\n        return {\n          id: maybeUser.id,\n          email: maybeUser.email,\n          name: maybeUser.name,\n          role: maybeUser.role,\n        };\n      },\n    }),\n  ],\n  callbacks: {\n    async signIn({ user, account, profile, email, credentials }) {\n      return true;\n    },\n    async redirect({ url, baseUrl }) {\n      return url.startsWith(baseUrl) ? url : baseUrl;\n    },\n    async jwt({ token, user, account, profile, isNewUser }) {\n      if (user) {\n        token.id = user.id;\n        token.role = user.role;\n      }\n\n      return token;\n    },\n    async session({ session, token, user }) {\n      const sess: Session = {\n        ...session,\n        user: {\n          ...session.user,\n          id: token.id as string,\n          role: token.role as string,\n        },\n      };\n\n      return sess;\n    },\n  },\n});\n"
  },
  {
    "path": "pages/api/auth/administrator/create.ts",
    "content": "import { NextApiRequest, NextApiResponse } from \"next\";\nimport nc from \"next-connect\";\nimport { hashPassword } from \"@lib/auth/passwords\";\nimport prisma from \"@db\";\n\nconst post = async (req: NextApiRequest, res: NextApiResponse) => {\n  try {\n    const admin = await prisma.user.create({\n      data: {\n        name: req.body.name,\n        email: req.body.email,\n        password: await hashPassword(req.body.password),\n        role: \"admin\",\n      },\n      select: {\n        id: true,\n        name: true,\n        email: true,\n      },\n    });\n\n    return res.status(200).json({\n      message: \"Admin created.\",\n      data: admin,\n    });\n  } catch (error) {\n    console.error(\"[api] auth/administrator/create\", error);\n    return res.status(500).json({ statusCode: 500, message: error.message });\n  }\n};\n\nexport default nc().post(post);\n"
  },
  {
    "path": "pages/api/users.ts",
    "content": "import { NextApiRequest, NextApiResponse } from \"next\";\nimport isEmpty from \"lodash/isEmpty\";\nimport nc from \"next-connect\";\nimport prisma, { Prisma } from \"@db\";\nimport { getSession } from \"@lib/auth/session\";\n\nconst handler = async (req: NextApiRequest, res: NextApiResponse) => {\n  const session = await getSession({ req });\n\n  if (!session) {\n    return res.status(401).json({\n      message: \"Unauthorized\",\n    });\n  }\n\n  const selectInput = isEmpty(req.body?.select) ? undefined : req.body?.select;\n  const whereInput = isEmpty(req.body?.where) ? undefined : req.body?.where;\n  const includeInput = isEmpty(req.body?.include)\n    ? undefined\n    : req.body?.include;\n  const orderByInput = isEmpty(req.body?.orderBy)\n    ? undefined\n    : req.body?.orderBy;\n  const cursorInput = isEmpty(req.body?.cursor) ? undefined : req.body?.cursor;\n  const takeInput = isEmpty(req.body?.take) ? undefined : req.body?.take;\n  const skipInput = isEmpty(req.body?.skip) ? undefined : req.body?.skip;\n  const distinctInput = isEmpty(req.body?.distinct)\n    ? undefined\n    : req.body?.distinct;\n\n  const findManyArgs: Prisma.UserFindManyArgs = {\n    select: selectInput,\n    where: whereInput,\n    include: includeInput,\n    orderBy: orderByInput,\n    cursor: cursorInput,\n    take: takeInput,\n    skip: skipInput,\n    distinct: distinctInput,\n  };\n\n  try {\n    const users = await prisma.user.findMany(findManyArgs);\n\n    return res.status(200).json(users);\n  } catch (error) {\n    console.error(\"[api] user\", error);\n    return res.status(500).json({ statusCode: 500, message: error.message });\n  }\n};\n\nexport default nc().get(handler);\n"
  },
  {
    "path": "pages/api/with-session-example.ts",
    "content": "import { getSession } from \"@lib/auth/session\";\n\nexport default async (req, res) => {\n  const session = await getSession({ req });\n\n  if (session) {\n    res.send({\n      content:\n        \"This is protected content. You can access this content because you are signed in.\",\n    });\n  } else {\n    res.send({\n      error: \"You must be sign in to view the protected content on this page.\",\n    });\n  }\n};\n"
  },
  {
    "path": "pages/client-redirect.tsx",
    "content": "import AppLayout from \"@lib/components/Layouts/AppLayout\";\nimport { useSession } from \"next-auth/react\";\nimport { useRouter } from \"next/router\";\n\nconst Page = () => {\n  const router = useRouter();\n  const { status, data: session } = useSession({\n    required: true,\n    onUnauthenticated() {\n      router.push(\"/\", \"/\", {});\n    },\n  });\n\n  if (status === \"loading\") {\n    return \"Loading or not authenticated...\";\n  }\n\n  return (\n    <>\n      <AppLayout>\n        <div>\n          <h1>\n            Hello, {`${session.user.name ?? session.user.email}`} This is a\n            protected route. You can see it because you're logged in.\n          </h1>\n        </div>\n        Client Side Rendering This page uses the useSession() React Hook. The\n        useSession() React Hook is easy to use and allows pages to render very\n        quickly. The advantage of this approach is that session state is shared\n        between pages by using the Provider in _app.js so that navigation\n        between pages using useSession() is very fast. The disadvantage of\n        useSession() is that it requires client side JavaScript.\n        <blockquote>\n          <p>This page is protected using the useSession hook.</p>\n          <p>Either way works.</p>\n          <p>\n            But in this case the session is <strong>not</strong> available on\n            the first render.\n          </p>\n        </blockquote>\n      </AppLayout>\n    </>\n  );\n};\n\nexport default Page;\n"
  },
  {
    "path": "pages/client.tsx",
    "content": "import AppLayout from \"@lib/components/Layouts/AppLayout\";\nimport { useSession } from \"next-auth/react\";\nimport Loader from \"@lib/components/Loader\";\n\nconst Page = () => {\n  const { status } = useSession({\n    required: false,\n  });\n\n  if (status === \"loading\") {\n    return <Loader />;\n  }\n\n  return (\n    <>\n      <AppLayout>\n        <blockquote>\n          <p>This page uses the useSession() React Hook.</p>\n\n          <p>\n            The useSession() React Hook is easy to use and allows pages to\n            render very quickly.\n          </p>\n\n          <p>\n            The advantage of this approach is that session state is shared\n            between pages by using the Provider in _app.js so that navigation\n            between pages using useSession() is very fast.\n          </p>\n\n          <p>\n            The disadvantage of useSession() is that it requires client side\n            JavaScript.\n          </p>\n          <p>This page is protected using the useSession hook.</p>\n          <p>Either way works.</p>\n          <p>\n            But in this case the session is <strong>not</strong> available on\n            the first render.\n          </p>\n        </blockquote>\n      </AppLayout>\n    </>\n  );\n};\n\nexport default Page;\n"
  },
  {
    "path": "pages/index.tsx",
    "content": "import AppLayout from \"@lib/components/Layouts/AppLayout\";\nimport Image from 'next/image';\n\nconst Page = () => {\n  return (\n    <>\n      <AppLayout>\n        {/* <blockquote> */}\n        <h1>Welcome to the PlanetScale Next.js Starter App!</h1>\n        <p>\n          This is an example site to demonstrate how to use{\" \"}\n          <a href={`https://next-auth.js.org`}>NextAuth.js</a> for\n          authentication with PlanetScale and Prisma.\n        </p>\n        <blockquote>\n          <p>  \n            You can find how to get started{\" \"}\n            <a href={`https://github.com/planetscale/nextjs-planetscale-starter`}>here</a>.\n          </p>\n        </blockquote>\n      </AppLayout>\n    </>\n  );\n};\n\nexport default Page;\n"
  },
  {
    "path": "pages/server-redirect.tsx",
    "content": "import AppLayout from \"@lib/components/Layouts/AppLayout\";\nimport { useSession } from \"next-auth/react\";\n\nconst Page = () => {\n  const { data: session } = useSession();\n  return (\n    <>\n      <AppLayout title=\"Server Redirect\">\n        <div>\n          <h1>\n            Hello, {`${session.user.name ?? session.user.email}`} This is a\n            protected route. You can see it because you're logged in.\n          </h1>\n        </div>\n        <blockquote>\n          <p>This page is protected using Page.auth = true</p>\n          <p>Either way works.</p>\n          <p>But in this case the session is available on the first render.</p>\n        </blockquote>\n      </AppLayout>\n    </>\n  );\n};\n\nPage.auth = {\n  redirectTo: \"/\",\n};\n\nexport default Page;\n"
  },
  {
    "path": "pages/server.tsx",
    "content": "import AppLayout from \"@lib/components/Layouts/AppLayout\";\nimport { useSession } from \"next-auth/react\";\nimport { getSession } from \"@lib/auth/session\";\n\nconst Page = () => {\n  const { status, data: session } = useSession({\n    required: false,\n  });\n\n  console.log(status, session);\n  return (\n    <>\n      <AppLayout title=\"Server\">\n        <blockquote>\n          <p>\n            This page uses the universal getSession() method in\n            getServerSideProps().\n          </p>\n\n          <p>\n            Using getSession() in getServerSideProps() is the recommended\n            approach if you need to support Server Side Rendering with\n            authentication.\n          </p>\n\n          <p>\n            The advantage of Server Side Rendering is this page does not require\n            client side JavaScript.\n          </p>\n\n          <p>\n            The disadvantage of Server Side Rendering is that this page is\n            slower to render.\n          </p>\n\n          <p>This page is protected using the useSession hook.</p>\n          <p>Either way works.</p>\n          <p>\n            But in this case the session is <strong>not</strong> available on\n            the first render.\n          </p>\n        </blockquote>\n      </AppLayout>\n    </>\n  );\n};\n\nexport async function getServerSideProps(context) {\n  return {\n    props: {\n      session: await getSession(context),\n    },\n  };\n}\n\nexport default Page;\n"
  },
  {
    "path": "pages/sign-in.tsx",
    "content": "import { filter } from \"lodash\";\nimport { GetServerSidePropsContext } from \"next\";\nimport {\n  getSession,\n  getCsrfToken,\n  signIn,\n  getProviders,\n} from \"next-auth/react\";\nimport Head from \"next/head\";\nimport React from \"react\";\nimport { useForm } from \"react-hook-form\";\n\nconst MINIMUM_ACTIVITY_TIMEOUT = 850;\ntype LoginFormValues = {\n  csrfToken: string;\n  email: string;\n  password: string;\n};\n\nexport default function Page({ csrfToken, providers }) {\n  const [isSubmitting, setSubmitting] = React.useState(false);\n\n  const { register, handleSubmit } = useForm();\n\n  const handleProviderSignIn = (provider) => {\n    signIn(provider.id);\n  };\n  const onSubmit = async (data: LoginFormValues) => {\n    setSubmitting(true);\n    try {\n      signIn(\"app-login\", {\n        callbackUrl: \"/\",\n        email: data.email,\n        password: data.password,\n      });\n\n      setTimeout(() => {\n        setSubmitting(false);\n      }, MINIMUM_ACTIVITY_TIMEOUT);\n    } catch (error) {\n      console.error(error);\n      //   setError(error)\n      setSubmitting(false);\n    }\n  };\n\n  return (\n    <div className=\"min-h-screen  flex flex-col justify-center py-12 sm:px-6 lg:px-8\">\n      <Head>\n        <title>Sign In</title>\n        <link rel=\"icon\" href=\"/favicon.ico\" />\n      </Head>\n      <div className=\"sm:mx-auto sm:w-full sm:max-w-md text-center py-12\">\n        <a href=\"/\">\n          <img\n            className=\"h-16 mx-auto\"\n            src=\"/assets/planet-scale.svg\"\n            alt=\"PlanetScale Logo\"\n          />\n        </a>\n      </div>\n      <div className=\" flex flex-col justify-center sm:px-6 lg:px-8\">\n        <div className=\"sm:mx-auto sm:w-full sm:max-w-md text-center\">\n          <h1 className=\"text-xl font-bold leading-7 text-gray-900 sm:leading-9 sm:truncate\">\n            Sign In\n          </h1>\n          <h2>Sign in with an existing account, or create new account.</h2>\n        </div>\n        <div className=\"mt-8 sm:mx-auto sm:w-full sm:max-w-md\">\n          <div className=\"py-8 px-4 mx-2 rounded-sm sm:px-10\">\n            <form\n              className=\"text-center my-12\"\n              onSubmit={handleSubmit(onSubmit)}\n            >\n              <input\n                name=\"csrfToken\"\n                {...register(\"csrfToken\")}\n                type=\"hidden\"\n                defaultValue={csrfToken}\n                hidden\n              />\n              <div className=\"\">\n                <label\n                  htmlFor=\"email\"\n                  className=\"block text-sm font-medium text-neutral-400\"\n                >\n                  Email address\n                </label>\n                <div className=\"mt-1\">\n                  <input\n                    id=\"email\"\n                    name=\"email\"\n                    type=\"email\"\n                    autoComplete=\"email\"\n                    required\n                    {...register(\"email\")}\n                    className=\"appearance-none w-full font-medium py-3 border-b border-t-0 border-l-0 border-r-0 border-dashed outline-none text-xl text-center leading-6 bg-transparent placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 transition duration-150 ease-in-out\"\n                  />\n                </div>\n              </div>\n\n              <div>\n                <div className=\"mt-8\">\n                  <label\n                    htmlFor=\"password\"\n                    className=\"block text-sm font-medium text-neutral-400\"\n                  >\n                    Password\n                  </label>\n                </div>\n                <div className=\"mt-1\">\n                  <input\n                    id=\"password\"\n                    name=\"password\"\n                    type=\"password\"\n                    autoComplete=\"current-password\"\n                    minLength={12}\n                    required\n                    {...register(\"password\")}\n                    className=\"appearance-none w-full font-medium py-3 border-b border-t-0 border-l-0 border-r-0 border-dashed outline-none text-xl text-center leading-6 bg-transparent placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 transition duration-150 ease-in-out\"\n                  />\n                </div>\n              </div>\n\n              <div className=\"mt-6 space-y-2 flex justify-center\">\n                <button\n                  type=\"submit\"\n                  disabled={isSubmitting}\n                  className=\"button button__md button__primary w-full\"\n                >\n                  {isSubmitting ? (\n                    <img src=\"/assets/loading.svg\" />\n                  ) : (\n                    <p>Sign in</p>\n                  )}\n                </button>\n              </div>\n            </form>\n            <section className=\"mt-8 text-center\">\n              <div className=\"flex flex-col mb-3\">\n                <hr className=\"h-0 border-t mt-1\" />\n                <div className=\"-mt-3 text-sm text-center\">\n                  <span className=\"px-2 bg-white text-secondary\">Or with</span>\n                </div>\n              </div>\n\n              <div className=\"grid grid-cols-2 gap-6\">\n                {providers.map((provider) => {\n                  return (\n                    <button\n                      key={provider}\n                      type=\"button\"\n                      onClick={() => handleProviderSignIn(provider)}\n                      className=\"button button__secondary inline-flex space-x-2\"\n                    >\n                      <img\n                        className=\"w-6 h-6\"\n                        src={`/assets/${provider.id}.svg`}\n                      />\n                      <p>{provider.name}</p>\n                    </button>\n                  );\n                })}\n              </div>\n            </section>\n          </div>\n        </div>\n      </div>\n    </div>\n  );\n}\n\nexport async function getServerSideProps(context: GetServerSidePropsContext) {\n  const session = await getSession(context);\n\n  if (session) {\n    return { redirect: { permanent: false, destination: \"/\" } };\n  }\n\n  const csrfToken = await getCsrfToken({ req: context.req });\n  const providers = filter(await getProviders(), (provider) => {\n    return provider.type !== \"credentials\";\n  });\n\n  return {\n    props: { csrfToken, providers },\n  };\n}\n"
  },
  {
    "path": "pages/with-session.tsx",
    "content": "import AppLayout from \"@lib/components/Layouts/AppLayout\";\nimport { useSession, signIn } from \"next-auth/react\";\nimport { useQuery } from \"react-query\";\nimport superagent from \"superagent\";\n\nconst Page = () => {\n  const { status, data: session } = useSession({\n    required: false,\n  });\n\n  const withSessionQuery = useQuery(\n    [\"with-session-example\", session],\n    async () => {\n      console.log(session);\n      const data = await superagent.get(\"/api/with-session-example\");\n\n      return data.body.content;\n    },\n    {\n      // The query will not execute until the session exists\n      enabled: !!session,\n    }\n  );\n\n  if (status === \"loading\") {\n    return \"Loading or not authenticated...\";\n  }\n\n  console.log(withSessionQuery);\n  if (!session) {\n    return (\n      <>\n        <AppLayout title=\"With Session\">\n          <blockquote>\n            <h1>Access Denied</h1>\n            <h1>\n              <button type=\"button\" onClick={() => signIn()}>\n                <a>Login</a>&nbsp;\n              </button>\n              to see a secret message\n            </h1>\n          </blockquote>\n        </AppLayout>\n      </>\n    );\n  }\n\n  return (\n    <>\n      <AppLayout title=\"With Session\">\n        <div>\n          <h1>\n            Hello, {`${session.user.name ?? session.user.email}`} You can see\n            this because you're logged in.\n          </h1>\n          <blockquote>\n            <p>\n              This example shows usage with React Query and protected api\n              routes.\n            </p>\n          </blockquote>\n          {withSessionQuery?.data && <p>{withSessionQuery.data}</p>}\n        </div>\n      </AppLayout>\n    </>\n  );\n};\n\nexport default Page;\n"
  },
  {
    "path": "postcss.config.js",
    "content": "module.exports = {\n  plugins: {\n    tailwindcss: {},\n    autoprefixer: {},\n  },\n}\n"
  },
  {
    "path": "tailwind.config.js",
    "content": "module.exports = {\n  mode: \"jit\",\n  purge: [\n    \"./pages/**/*.{js,ts,jsx,tsx}\",\n    \"./lib/components/**/*.{js,ts,jsx,tsx}\",\n  ],\n  darkMode: \"class\",\n  theme: {\n    extend: {},\n  },\n  variants: {\n    extend: {},\n  },\n  plugins: [require(\"@tailwindcss/forms\")],\n};\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"target\": \"es5\",\n    \"lib\": [\"dom\", \"dom.iterable\", \"esnext\"],\n    \"baseUrl\": \".\",\n    \"paths\": {\n      \"@api/*\": [\"pages/api/*\"],\n      \"@lib/*\": [\"lib/*\"],\n      \"@components/*\": [\"lib/components/*\"],\n      \"@components\": [\"lib/components/index\"],\n      \"@db/*\": [\"db/*\"],\n      \"@db\": [\"db/index\"]\n    },\n    \"allowJs\": true,\n    \"skipLibCheck\": true,\n    \"strict\": false,\n    \"forceConsistentCasingInFileNames\": true,\n    \"noEmit\": true,\n    \"esModuleInterop\": true,\n    \"module\": \"esnext\",\n    \"moduleResolution\": \"node\",\n    \"resolveJsonModule\": true,\n    \"isolatedModules\": true,\n    \"jsx\": \"preserve\",\n    \"incremental\": true\n  },\n  \"include\": [\"next-env.d.ts\", \"**/*.ts\", \"**/*.tsx\"],\n  \"exclude\": [\"node_modules\"]\n}\n"
  }
]