From b61622019e95f1642fcf48875498aa31f602c726 Mon Sep 17 00:00:00 2001 From: Jacob Fletcher Date: Tue, 26 Nov 2024 14:07:56 -0500 Subject: [PATCH] chore(examples): removes external auth examples (#8605) In effort to keep the Examples Directory as easy to navigate as possible, and to keep the Payload Monorepo only as verbose as it needs to be, we need to remove all alternatives from the Examples Directory. This includes setups that interact with Payload from a standalone server, keeping only the Payload recommended "combined" Next.js + Payload setups. This will also be applied to all other examples that use this setup, i.e. draft preview, live preview, etc. --- docs/admin/overview.mdx | 2 +- docs/examples/overview.mdx | 18 +- examples/auth/{payload => }/.env.example | 0 examples/auth/{payload => }/.eslintignore | 0 examples/auth/{payload => }/.eslintrc.cjs | 0 examples/auth/{payload => }/.gitignore | 0 examples/auth/{payload => }/README.md | 13 +- examples/auth/next-app/.env.example | 1 - examples/auth/next-app/.eslintrc.cjs | 7 - examples/auth/next-app/.gitignore | 6 - examples/auth/next-app/README.md | 44 - .../next-app/app/_components/Button/index.tsx | 75 - .../next-app/app/_components/Gutter/index.tsx | 33 - .../app/_components/Header/Nav/index.tsx | 38 - .../next-app/app/_components/Header/index.tsx | 33 - .../next-app/app/_components/Input/index.tsx | 55 - .../app/_components/Message/index.tsx | 33 - .../app/_components/RenderParams/index.tsx | 29 - .../app/_components/RichText/index.tsx | 19 - .../app/_components/RichText/serialize.tsx | 92 - .../auth/next-app/app/_providers/Auth/gql.ts | 34 - .../next-app/app/_providers/Auth/index.tsx | 180 - .../auth/next-app/app/_providers/Auth/rest.ts | 34 - .../next-app/app/_providers/Auth/types.ts | 31 - .../auth/next-app/app/_utilities/getMeUser.ts | 41 - .../app/account/AccountForm/index.tsx | 155 - examples/auth/next-app/app/account/page.tsx | 34 - .../CreateAccountForm/index.tsx | 121 - .../auth/next-app/app/create-account/page.tsx | 24 - examples/auth/next-app/app/layout.tsx | 28 - .../next-app/app/login/LoginForm/index.tsx | 96 - examples/auth/next-app/app/login/page.tsx | 22 - .../next-app/app/logout/LogoutPage/index.tsx | 42 - examples/auth/next-app/app/logout/page.tsx | 14 - examples/auth/next-app/app/page.tsx | 45 - examples/auth/next-app/app/payload-types.ts | 30 - .../RecoverPasswordForm/index.tsx | 91 - .../next-app/app/recover-password/page.tsx | 14 - .../ResetPasswordForm/index.tsx | 87 - .../auth/next-app/app/reset-password/page.tsx | 16 - examples/auth/next-app/next.config.js | 4 - examples/auth/next-app/package.json | 40 - examples/auth/next-app/pnpm-lock.yaml | 3766 ----------------- examples/auth/next-app/public/favicon.ico | Bin 17223 -> 0 bytes examples/auth/next-app/public/favicon.svg | 15 - examples/auth/next-app/tsconfig.json | 32 - examples/auth/{next-app => }/next-env.d.ts | 0 examples/auth/next-pages/.env.example | 1 - examples/auth/next-pages/.eslintrc.cjs | 4 - examples/auth/next-pages/.gitignore | 6 - examples/auth/next-pages/README.md | 44 - examples/auth/next-pages/next-env.d.ts | 5 - examples/auth/next-pages/next.config.js | 10 - examples/auth/next-pages/package.json | 38 - examples/auth/next-pages/pnpm-lock.yaml | 3144 -------------- examples/auth/next-pages/public/favicon.ico | Bin 17223 -> 0 bytes examples/auth/next-pages/public/favicon.svg | 15 - .../src/components/Button/index.module.scss | 40 - .../src/components/Button/index.tsx | 73 - .../src/components/Gutter/index.module.scss | 13 - .../src/components/Gutter/index.tsx | 33 - .../components/Header/Nav/index.module.scss | 20 - .../src/components/Header/Nav/index.tsx | 36 - .../src/components/Header/index.module.scss | 22 - .../src/components/Header/index.tsx | 33 - .../src/components/Input/index.module.scss | 56 - .../next-pages/src/components/Input/index.tsx | 55 - .../src/components/Message/index.module.scss | 46 - .../src/components/Message/index.tsx | 33 - .../src/components/RenderParams/index.tsx | 25 - .../src/components/RichText/index.module.scss | 9 - .../src/components/RichText/index.tsx | 19 - .../src/components/RichText/serialize.tsx | 92 - examples/auth/next-pages/src/css/app.scss | 117 - examples/auth/next-pages/src/css/colors.scss | 103 - examples/auth/next-pages/src/css/common.scss | 1 - examples/auth/next-pages/src/css/queries.scss | 28 - examples/auth/next-pages/src/css/theme.scss | 241 -- examples/auth/next-pages/src/css/type.scss | 110 - examples/auth/next-pages/src/pages/_app.tsx | 24 - .../src/pages/account/index.module.scss | 32 - .../next-pages/src/pages/account/index.tsx | 170 - .../pages/create-account/index.module.scss | 26 - .../src/pages/create-account/index.tsx | 127 - examples/auth/next-pages/src/pages/index.tsx | 45 - .../src/pages/login/index.module.scss | 30 - .../auth/next-pages/src/pages/login/index.tsx | 102 - .../src/pages/logout/index.module.scss | 3 - .../next-pages/src/pages/logout/index.tsx | 45 - .../pages/recover-password/index.module.scss | 26 - .../src/pages/recover-password/index.tsx | 92 - .../pages/reset-password/index.module.scss | 17 - .../src/pages/reset-password/index.tsx | 92 - examples/auth/next-pages/src/payload-types.ts | 30 - .../auth/next-pages/src/providers/Auth/gql.ts | 34 - .../next-pages/src/providers/Auth/index.tsx | 178 - .../next-pages/src/providers/Auth/rest.ts | 34 - .../next-pages/src/providers/Auth/types.ts | 31 - examples/auth/next-pages/tsconfig.json | 30 - examples/auth/{payload => }/next.config.mjs | 0 examples/auth/{payload => }/package.json | 0 examples/auth/payload/next-env.d.ts | 5 - .../_components/Button/index.module.scss | 40 - .../_components/Gutter/index.module.scss | 13 - .../_components/Header/Nav/index.module.scss | 20 - .../_components/Header/index.module.scss | 22 - .../app/(app)/_components/Header/index.tsx | 33 - .../(app)/_components/Input/index.module.scss | 56 - .../_components/Message/index.module.scss | 46 - .../_components/RichText/index.module.scss | 9 - .../auth/payload/src/app/(app)/_css/app.scss | 117 - .../payload/src/app/(app)/_css/colors.scss | 103 - .../payload/src/app/(app)/_css/common.scss | 1 - .../payload/src/app/(app)/_css/queries.scss | 28 - .../payload/src/app/(app)/_css/theme.scss | 241 -- .../auth/payload/src/app/(app)/_css/type.scss | 110 - .../account/AccountForm/index.module.scss | 24 - .../src/app/(app)/account/index.module.scss | 7 - .../CreateAccountForm/index.module.scss | 22 - .../(app)/create-account/index.module.scss | 5 - .../(app)/login/LoginForm/index.module.scss | 22 - .../src/app/(app)/login/index.module.scss | 9 - .../src/app/(app)/logout/index.module.scss | 3 - .../RecoverPasswordForm/index.module.scss | 22 - .../(app)/recover-password/index.module.scss | 5 - .../ResetPasswordForm/index.module.scss | 13 - .../(app)/reset-password/index.module.scss | 3 - examples/auth/{payload => }/pnpm-lock.yaml | 0 .../_components/Button/index.module.scss | 0 .../app/(app)/_components/Button/index.tsx | 2 +- .../_components/Gutter/index.module.scss | 0 .../app/(app)/_components/Gutter/index.tsx | 0 .../_components/Header/Nav/index.module.scss | 0 .../(app)/_components/Header/Nav/index.tsx | 0 .../_components/Header/index.module.scss | 0 .../_components/HydrateClientUser/index.tsx | 0 .../_components/Input/index.module.scss | 0 .../src/app/(app)/_components/Input/index.tsx | 2 +- .../_components/Message/index.module.scss | 0 .../app/(app)/_components/Message/index.tsx | 0 .../(app)/_components/RenderParams/index.tsx | 0 .../_components/RichText/index.module.scss | 0 .../app/(app)/_components/RichText/index.tsx | 0 .../(app)/_components/RichText/serialize.tsx | 2 +- .../app => src/app/(app)}/_css/app.scss | 0 .../app => src/app/(app)}/_css/colors.scss | 0 .../app => src/app/(app)}/_css/common.scss | 0 .../app => src/app/(app)}/_css/queries.scss | 0 .../app => src/app/(app)}/_css/theme.scss | 0 .../app => src/app/(app)}/_css/type.scss | 0 .../src/app/(app)/_providers/Auth/gql.ts | 0 .../src/app/(app)/_providers/Auth/index.tsx | 8 +- .../src/app/(app)/_providers/Auth/rest.ts | 2 +- .../src/app/(app)/_providers/Auth/types.ts | 16 +- .../account/AccountForm/index.module.scss | 0 .../app/(app)/account/AccountForm/index.tsx | 0 .../app/(app)}/account/index.module.scss | 0 .../src/app/(app)/account/page.tsx | 0 .../CreateAccountForm/index.module.scss | 0 .../CreateAccountForm/index.tsx | 4 +- .../(app)}/create-account/index.module.scss | 0 .../src/app/(app)/create-account/page.tsx | 0 .../{payload => }/src/app/(app)/layout.tsx | 0 .../(app)}/login/LoginForm/index.module.scss | 0 .../src/app/(app)/login/LoginForm/index.tsx | 4 +- .../app/(app)}/login/index.module.scss | 0 .../src/app/(app)/login/page.tsx | 0 .../src/app/(app)/logout/LogoutPage/index.tsx | 0 .../app/(app)}/logout/index.module.scss | 0 .../src/app/(app)/logout/page.tsx | 0 .../auth/{payload => }/src/app/(app)/page.tsx | 0 .../RecoverPasswordForm/index.module.scss | 0 .../RecoverPasswordForm/index.tsx | 0 .../(app)}/recover-password/index.module.scss | 0 .../src/app/(app)/recover-password/page.tsx | 0 .../ResetPasswordForm/index.module.scss | 0 .../ResetPasswordForm/index.tsx | 0 .../(app)}/reset-password/index.module.scss | 0 .../src/app/(app)/reset-password/page.tsx | 0 .../admin/[[...segments]]/not-found.tsx | 0 .../(payload)/admin/[[...segments]]/page.tsx | 0 .../src/app/(payload)/api/[...slug]/route.ts | 0 .../(payload)/api/graphql-playground/route.ts | 0 .../src/app/(payload)/api/graphql/route.ts | 0 .../src/app/(payload)/custom.scss | 0 .../src/app/(payload)/layout.tsx | 0 .../{payload => }/src/collections/Users.ts | 0 .../src/collections/access/admins.ts | 0 .../src/collections/access/adminsAndUser.ts | 0 .../src/collections/access/anyone.ts | 0 .../src/collections/access/checkRole.ts | 2 +- .../src/collections/hooks/loginAfterCreate.ts | 0 .../src/collections/hooks/protectRoles.ts | 2 +- .../src/components/BeforeLogin/index.tsx | 0 .../auth/{payload => }/src/migrations/seed.ts | 0 .../auth/{payload => }/src/payload-types.ts | 0 .../auth/{payload => }/src/payload.config.ts | 0 examples/auth/{payload => }/tsconfig.json | 0 examples/custom-components/README.md | 2 +- examples/multi-tenant/README.md | 2 +- templates/website/README.md | 2 +- templates/with-vercel-website/README.md | 2 +- 202 files changed, 30 insertions(+), 12135 deletions(-) rename examples/auth/{payload => }/.env.example (100%) rename examples/auth/{payload => }/.eslintignore (100%) rename examples/auth/{payload => }/.eslintrc.cjs (100%) rename examples/auth/{payload => }/.gitignore (100%) rename examples/auth/{payload => }/README.md (90%) delete mode 100644 examples/auth/next-app/.env.example delete mode 100644 examples/auth/next-app/.eslintrc.cjs delete mode 100644 examples/auth/next-app/.gitignore delete mode 100644 examples/auth/next-app/README.md delete mode 100644 examples/auth/next-app/app/_components/Button/index.tsx delete mode 100644 examples/auth/next-app/app/_components/Gutter/index.tsx delete mode 100644 examples/auth/next-app/app/_components/Header/Nav/index.tsx delete mode 100644 examples/auth/next-app/app/_components/Header/index.tsx delete mode 100644 examples/auth/next-app/app/_components/Input/index.tsx delete mode 100644 examples/auth/next-app/app/_components/Message/index.tsx delete mode 100644 examples/auth/next-app/app/_components/RenderParams/index.tsx delete mode 100644 examples/auth/next-app/app/_components/RichText/index.tsx delete mode 100644 examples/auth/next-app/app/_components/RichText/serialize.tsx delete mode 100644 examples/auth/next-app/app/_providers/Auth/gql.ts delete mode 100644 examples/auth/next-app/app/_providers/Auth/index.tsx delete mode 100644 examples/auth/next-app/app/_providers/Auth/rest.ts delete mode 100644 examples/auth/next-app/app/_providers/Auth/types.ts delete mode 100644 examples/auth/next-app/app/_utilities/getMeUser.ts delete mode 100644 examples/auth/next-app/app/account/AccountForm/index.tsx delete mode 100644 examples/auth/next-app/app/account/page.tsx delete mode 100644 examples/auth/next-app/app/create-account/CreateAccountForm/index.tsx delete mode 100644 examples/auth/next-app/app/create-account/page.tsx delete mode 100644 examples/auth/next-app/app/layout.tsx delete mode 100644 examples/auth/next-app/app/login/LoginForm/index.tsx delete mode 100644 examples/auth/next-app/app/login/page.tsx delete mode 100644 examples/auth/next-app/app/logout/LogoutPage/index.tsx delete mode 100644 examples/auth/next-app/app/logout/page.tsx delete mode 100644 examples/auth/next-app/app/page.tsx delete mode 100644 examples/auth/next-app/app/payload-types.ts delete mode 100644 examples/auth/next-app/app/recover-password/RecoverPasswordForm/index.tsx delete mode 100644 examples/auth/next-app/app/recover-password/page.tsx delete mode 100644 examples/auth/next-app/app/reset-password/ResetPasswordForm/index.tsx delete mode 100644 examples/auth/next-app/app/reset-password/page.tsx delete mode 100644 examples/auth/next-app/next.config.js delete mode 100644 examples/auth/next-app/package.json delete mode 100644 examples/auth/next-app/pnpm-lock.yaml delete mode 100644 examples/auth/next-app/public/favicon.ico delete mode 100644 examples/auth/next-app/public/favicon.svg delete mode 100644 examples/auth/next-app/tsconfig.json rename examples/auth/{next-app => }/next-env.d.ts (100%) delete mode 100644 examples/auth/next-pages/.env.example delete mode 100644 examples/auth/next-pages/.eslintrc.cjs delete mode 100644 examples/auth/next-pages/.gitignore delete mode 100644 examples/auth/next-pages/README.md delete mode 100644 examples/auth/next-pages/next-env.d.ts delete mode 100644 examples/auth/next-pages/next.config.js delete mode 100644 examples/auth/next-pages/package.json delete mode 100644 examples/auth/next-pages/pnpm-lock.yaml delete mode 100644 examples/auth/next-pages/public/favicon.ico delete mode 100644 examples/auth/next-pages/public/favicon.svg delete mode 100644 examples/auth/next-pages/src/components/Button/index.module.scss delete mode 100644 examples/auth/next-pages/src/components/Button/index.tsx delete mode 100644 examples/auth/next-pages/src/components/Gutter/index.module.scss delete mode 100644 examples/auth/next-pages/src/components/Gutter/index.tsx delete mode 100644 examples/auth/next-pages/src/components/Header/Nav/index.module.scss delete mode 100644 examples/auth/next-pages/src/components/Header/Nav/index.tsx delete mode 100644 examples/auth/next-pages/src/components/Header/index.module.scss delete mode 100644 examples/auth/next-pages/src/components/Header/index.tsx delete mode 100644 examples/auth/next-pages/src/components/Input/index.module.scss delete mode 100644 examples/auth/next-pages/src/components/Input/index.tsx delete mode 100644 examples/auth/next-pages/src/components/Message/index.module.scss delete mode 100644 examples/auth/next-pages/src/components/Message/index.tsx delete mode 100644 examples/auth/next-pages/src/components/RenderParams/index.tsx delete mode 100644 examples/auth/next-pages/src/components/RichText/index.module.scss delete mode 100644 examples/auth/next-pages/src/components/RichText/index.tsx delete mode 100644 examples/auth/next-pages/src/components/RichText/serialize.tsx delete mode 100644 examples/auth/next-pages/src/css/app.scss delete mode 100644 examples/auth/next-pages/src/css/colors.scss delete mode 100644 examples/auth/next-pages/src/css/common.scss delete mode 100644 examples/auth/next-pages/src/css/queries.scss delete mode 100644 examples/auth/next-pages/src/css/theme.scss delete mode 100644 examples/auth/next-pages/src/css/type.scss delete mode 100644 examples/auth/next-pages/src/pages/_app.tsx delete mode 100644 examples/auth/next-pages/src/pages/account/index.module.scss delete mode 100644 examples/auth/next-pages/src/pages/account/index.tsx delete mode 100644 examples/auth/next-pages/src/pages/create-account/index.module.scss delete mode 100644 examples/auth/next-pages/src/pages/create-account/index.tsx delete mode 100644 examples/auth/next-pages/src/pages/index.tsx delete mode 100644 examples/auth/next-pages/src/pages/login/index.module.scss delete mode 100644 examples/auth/next-pages/src/pages/login/index.tsx delete mode 100644 examples/auth/next-pages/src/pages/logout/index.module.scss delete mode 100644 examples/auth/next-pages/src/pages/logout/index.tsx delete mode 100644 examples/auth/next-pages/src/pages/recover-password/index.module.scss delete mode 100644 examples/auth/next-pages/src/pages/recover-password/index.tsx delete mode 100644 examples/auth/next-pages/src/pages/reset-password/index.module.scss delete mode 100644 examples/auth/next-pages/src/pages/reset-password/index.tsx delete mode 100644 examples/auth/next-pages/src/payload-types.ts delete mode 100644 examples/auth/next-pages/src/providers/Auth/gql.ts delete mode 100644 examples/auth/next-pages/src/providers/Auth/index.tsx delete mode 100644 examples/auth/next-pages/src/providers/Auth/rest.ts delete mode 100644 examples/auth/next-pages/src/providers/Auth/types.ts delete mode 100644 examples/auth/next-pages/tsconfig.json rename examples/auth/{payload => }/next.config.mjs (100%) rename examples/auth/{payload => }/package.json (100%) delete mode 100644 examples/auth/payload/next-env.d.ts delete mode 100644 examples/auth/payload/src/app/(app)/_components/Button/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/_components/Gutter/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/_components/Header/Nav/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/_components/Header/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/_components/Header/index.tsx delete mode 100644 examples/auth/payload/src/app/(app)/_components/Input/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/_components/Message/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/_components/RichText/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/_css/app.scss delete mode 100644 examples/auth/payload/src/app/(app)/_css/colors.scss delete mode 100644 examples/auth/payload/src/app/(app)/_css/common.scss delete mode 100644 examples/auth/payload/src/app/(app)/_css/queries.scss delete mode 100644 examples/auth/payload/src/app/(app)/_css/theme.scss delete mode 100644 examples/auth/payload/src/app/(app)/_css/type.scss delete mode 100644 examples/auth/payload/src/app/(app)/account/AccountForm/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/account/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/create-account/CreateAccountForm/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/create-account/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/login/LoginForm/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/login/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/logout/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/recover-password/RecoverPasswordForm/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/recover-password/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/reset-password/ResetPasswordForm/index.module.scss delete mode 100644 examples/auth/payload/src/app/(app)/reset-password/index.module.scss rename examples/auth/{payload => }/pnpm-lock.yaml (100%) rename examples/auth/{next-app/app => src/app/(app)}/_components/Button/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/_components/Button/index.tsx (96%) rename examples/auth/{next-app/app => src/app/(app)}/_components/Gutter/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/_components/Gutter/index.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/_components/Header/Nav/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/_components/Header/Nav/index.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/_components/Header/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/_components/HydrateClientUser/index.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/_components/Input/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/_components/Input/index.tsx (95%) rename examples/auth/{next-app/app => src/app/(app)}/_components/Message/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/_components/Message/index.tsx (100%) rename examples/auth/{payload => }/src/app/(app)/_components/RenderParams/index.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/_components/RichText/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/_components/RichText/index.tsx (100%) rename examples/auth/{payload => }/src/app/(app)/_components/RichText/serialize.tsx (97%) rename examples/auth/{next-app/app => src/app/(app)}/_css/app.scss (100%) rename examples/auth/{next-app/app => src/app/(app)}/_css/colors.scss (100%) rename examples/auth/{next-app/app => src/app/(app)}/_css/common.scss (100%) rename examples/auth/{next-app/app => src/app/(app)}/_css/queries.scss (100%) rename examples/auth/{next-app/app => src/app/(app)}/_css/theme.scss (100%) rename examples/auth/{next-app/app => src/app/(app)}/_css/type.scss (100%) rename examples/auth/{payload => }/src/app/(app)/_providers/Auth/gql.ts (100%) rename examples/auth/{payload => }/src/app/(app)/_providers/Auth/index.tsx (94%) rename examples/auth/{payload => }/src/app/(app)/_providers/Auth/rest.ts (94%) rename examples/auth/{payload => }/src/app/(app)/_providers/Auth/types.ts (62%) rename examples/auth/{next-app/app => src/app/(app)}/account/AccountForm/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/account/AccountForm/index.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/account/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/account/page.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/create-account/CreateAccountForm/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/create-account/CreateAccountForm/index.tsx (95%) rename examples/auth/{next-app/app => src/app/(app)}/create-account/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/create-account/page.tsx (100%) rename examples/auth/{payload => }/src/app/(app)/layout.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/login/LoginForm/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/login/LoginForm/index.tsx (96%) rename examples/auth/{next-app/app => src/app/(app)}/login/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/login/page.tsx (100%) rename examples/auth/{payload => }/src/app/(app)/logout/LogoutPage/index.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/logout/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/logout/page.tsx (100%) rename examples/auth/{payload => }/src/app/(app)/page.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/recover-password/RecoverPasswordForm/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/recover-password/RecoverPasswordForm/index.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/recover-password/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/recover-password/page.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/reset-password/ResetPasswordForm/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/reset-password/ResetPasswordForm/index.tsx (100%) rename examples/auth/{next-app/app => src/app/(app)}/reset-password/index.module.scss (100%) rename examples/auth/{payload => }/src/app/(app)/reset-password/page.tsx (100%) rename examples/auth/{payload => }/src/app/(payload)/admin/[[...segments]]/not-found.tsx (100%) rename examples/auth/{payload => }/src/app/(payload)/admin/[[...segments]]/page.tsx (100%) rename examples/auth/{payload => }/src/app/(payload)/api/[...slug]/route.ts (100%) rename examples/auth/{payload => }/src/app/(payload)/api/graphql-playground/route.ts (100%) rename examples/auth/{payload => }/src/app/(payload)/api/graphql/route.ts (100%) rename examples/auth/{payload => }/src/app/(payload)/custom.scss (100%) rename examples/auth/{payload => }/src/app/(payload)/layout.tsx (100%) rename examples/auth/{payload => }/src/collections/Users.ts (100%) rename examples/auth/{payload => }/src/collections/access/admins.ts (100%) rename examples/auth/{payload => }/src/collections/access/adminsAndUser.ts (100%) rename examples/auth/{payload => }/src/collections/access/anyone.ts (100%) rename examples/auth/{payload => }/src/collections/access/checkRole.ts (94%) rename examples/auth/{payload => }/src/collections/hooks/loginAfterCreate.ts (100%) rename examples/auth/{payload => }/src/collections/hooks/protectRoles.ts (87%) rename examples/auth/{payload => }/src/components/BeforeLogin/index.tsx (100%) rename examples/auth/{payload => }/src/migrations/seed.ts (100%) rename examples/auth/{payload => }/src/payload-types.ts (100%) rename examples/auth/{payload => }/src/payload.config.ts (100%) rename examples/auth/{payload => }/tsconfig.json (100%) diff --git a/docs/admin/overview.mdx b/docs/admin/overview.mdx index dd3fd8a9ce..a84ad55318 100644 --- a/docs/admin/overview.mdx +++ b/docs/admin/overview.mdx @@ -143,7 +143,7 @@ It is also possible to allow multiple user types into the Admin Panel with limit - `super-admin` - full access to the Admin Panel to perform any action - `editor` - limited access to the Admin Panel to only manage content -To do this, add a `roles` or similar field to your auth-enabled Collection, then use the `access.admin` property to grant or deny access based on the value of that field. See [Access Control](/docs/access-control/overview) for full details. For a complete, working example of role-based access control, check out the official [Auth Example](https://github.com/payloadcms/payload/tree/main/examples/auth/payload). +To do this, add a `roles` or similar field to your auth-enabled Collection, then use the `access.admin` property to grant or deny access based on the value of that field. See [Access Control](/docs/access-control/overview) for full details. For a complete, working example of role-based access control, check out the official [Auth Example](https://github.com/payloadcms/payload/tree/main/examples/auth). ## Customizing Routes diff --git a/docs/examples/overview.mdx b/docs/examples/overview.mdx index f77c417f4c..79cbb42ee0 100644 --- a/docs/examples/overview.mdx +++ b/docs/examples/overview.mdx @@ -6,9 +6,7 @@ desc: keywords: example, examples, starter, boilerplate, template, templates --- -Payload provides a vast array of examples to help you get started with your project no matter what you are working on. These examples are designed to be easy to get up and running, and to be easy to understand. They showcase nothing more than the specific features being demonstrated so you can easily decipher what is going on. - -Examples are changing every day, so be sure to check back often to see what new examples have been added. If you have a specific example you would like to see, please feel free to start a new [Discussion](https://github.com/payloadcms/payload/discussions) or open a new [PR](https://github.com/payloadcms/payload/pulls) to add it yourself. +Payload provides a vast array of examples to help you get started with your project no matter what you are working on. These examples are designed to be easy to get up and running, and to be easy to understand. They showcase nothing more than the specific features being demonstrated so you can easily decipher precisely what is going on. - [Auth](https://github.com/payloadcms/payload/tree/main/examples/auth) - [Custom Components](https://github.com/payloadcms/payload/tree/main/examples/custom-components) @@ -21,16 +19,4 @@ Examples are changing every day, so be sure to check back often to see what new - [Tests](https://github.com/payloadcms/payload/tree/main/examples/testing) - [White-label Admin UI](https://github.com/payloadcms/payload/tree/main/examples/whitelabel) -When necessary, some examples include a front-end. Examples that require a front-end share this folder structure: - -```plaintext -example/ -├── payload/ -├── next-app/ -├── next-pages/ -├── react-router/ -├── vue/ -├── svelte/ -``` - -Where `payload` is your Payload project, and the other directories are dedicated to their respective front-end framework. We are adding new examples every day, so if your framework of choice is not yet supported in any particular example, please feel free to start a new [Discussion](https://github.com/payloadcms/payload/discussions) or open a new [PR](https://github.com/payloadcms/payload/pulls) to add it yourself. +We are adding new examples every day, so if your particular use case is not demonstrated in any existing example, please feel free to start a new [Discussion](https://github.com/payloadcms/payload/discussions) or open a new [PR](https://github.com/payloadcms/payload/pulls) to add it yourself. diff --git a/examples/auth/payload/.env.example b/examples/auth/.env.example similarity index 100% rename from examples/auth/payload/.env.example rename to examples/auth/.env.example diff --git a/examples/auth/payload/.eslintignore b/examples/auth/.eslintignore similarity index 100% rename from examples/auth/payload/.eslintignore rename to examples/auth/.eslintignore diff --git a/examples/auth/payload/.eslintrc.cjs b/examples/auth/.eslintrc.cjs similarity index 100% rename from examples/auth/payload/.eslintrc.cjs rename to examples/auth/.eslintrc.cjs diff --git a/examples/auth/payload/.gitignore b/examples/auth/.gitignore similarity index 100% rename from examples/auth/payload/.gitignore rename to examples/auth/.gitignore diff --git a/examples/auth/payload/README.md b/examples/auth/README.md similarity index 90% rename from examples/auth/payload/README.md rename to examples/auth/README.md index 16bf667d58..e71790242c 100644 --- a/examples/auth/payload/README.md +++ b/examples/auth/README.md @@ -2,14 +2,7 @@ This [Payload Auth Example](https://github.com/payloadcms/payload/tree/main/examples/auth) demonstrates how to implement [Payload Authentication](https://payloadcms.com/docs/authentication/overview) into all types of applications. Follow the [Quick Start](#quick-start) to get up and running quickly. -**IMPORTANT—This example includes a fully integrated Next.js App Router front-end that runs on the same server as Payload.** If you are working on an application running on an entirely separate server, there are various fully working, separately running front-ends made explicitly for this example, including: - -- [Next.js App Router](../next-app) -- [Next.js Pages Router](../next-pages) - -Those applications run directly alongside this one. Follow the instructions in each respective README to get started. If you are setting up authentication for another front-end, please consider contributing to this repo with your own example! - -To learn more about this, [check out how Payload can be used in its various headless capacities](https://payloadcms.com/blog/the-ultimate-guide-to-using-nextjs-with-payload). +**IMPORTANT—This example includes a fully integrated Next.js App Router front-end that runs on the same server as Payload.** If you are working on an application running on an entirely separate server, the principals are generally the same. To learn more about this, [check out how Payload can be used in its various headless capacities](https://payloadcms.com/blog/the-ultimate-guide-to-using-nextjs-with-payload). ## Quick Start @@ -132,7 +125,3 @@ If you are using an integrated Next.js setup, the easiest way to deploy your Nex ## Questions If you have any issues or questions, reach out to us on [Discord](https://discord.com/invite/payload) or start a [GitHub discussion](https://github.com/payloadcms/payload/discussions). - -``` - -``` diff --git a/examples/auth/next-app/.env.example b/examples/auth/next-app/.env.example deleted file mode 100644 index c72201c91b..0000000000 --- a/examples/auth/next-app/.env.example +++ /dev/null @@ -1 +0,0 @@ -NEXT_PUBLIC_PAYLOAD_URL=http://localhost:3000 diff --git a/examples/auth/next-app/.eslintrc.cjs b/examples/auth/next-app/.eslintrc.cjs deleted file mode 100644 index b22424b3ed..0000000000 --- a/examples/auth/next-app/.eslintrc.cjs +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - root: true, - extends: ['plugin:@next/next/recommended', '@payloadcms'], - rules: { - 'import/extensions': 'off', - }, -} diff --git a/examples/auth/next-app/.gitignore b/examples/auth/next-app/.gitignore deleted file mode 100644 index 233d5a4d02..0000000000 --- a/examples/auth/next-app/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -.next -dist -build -node_modules -.env -package-lock.json diff --git a/examples/auth/next-app/README.md b/examples/auth/next-app/README.md deleted file mode 100644 index 26fd76fb84..0000000000 --- a/examples/auth/next-app/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# Payload Auth Example Front-End - -This is a [Next.js](https://nextjs.org) [App Router](https://nextjs.org/docs/app) front-end made explicitly for the [Payload Auth Example](https://github.com/payloadcms/payload/tree/main/examples/auth). This example demonstrates how to authenticate your Next.js app using [Payload Authentication](https://payloadcms.com/docs/authentication/overview). - -> This example uses the App Router, the latest API of Next.js. If your app is using the legacy [Pages Router](https://nextjs.org/docs/pages), check out the official [Pages Router Example](https://github.com/payloadcms/payload/tree/main/examples/auth/next-pages). - -**IMPORTANT—This application runs on a different server as Payload and establishes a connection from another domain or port over HTTP.** For an integrated setup that runs on a single server and uses the [Local API](https://payloadcms.com/docs/local-api/overview#local-api), check out [how to serve Payload alongside Next.js](https://github.com/payloadcms/payload/tree/main/examples/auth/payload). To learn more about this, check out [how Payload can be used in its various headless capacities](https://payloadcms.com/blog/the-ultimate-guide-to-using-nextjs-with-payload). - -## Getting Started - -### Payload - -First you'll need a running Payload app. There is one made explicitly for this example and [can be found here](https://github.com/payloadcms/payload/tree/main/examples/auth/payload). If you have not done so already, clone it down and follow the setup instructions there. This will provide all the necessary APIs that your Next.js app requires for authentication. - -### Next.js - -1. Clone this repo -2. `cd` into this directory and run `pnpm i --ignore-workspace`\*, `yarn`, or `npm install` - > \*If you are running using pnpm within the Payload Monorepo, the `--ignore-workspace` flag is needed so that pnpm generates a lockfile in this example's directory despite the fact that one exists in root. -3. `cp .env.example .env` to copy the example environment variables -4. `pnpm dev`, `yarn dev`, or `npm run dev` to start the server -5. `open http://localhost:3001` to see the result - -Once running, a user is automatically seeded in your local environment with some basic instructions. See the [Payload Auth Example](https://github.com/payloadcms/payload/tree/main/examples/auth) for full details. - -## Learn More - -To learn more about Payload and Next.js, take a look at the following resources: - -- [Payload Documentation](https://payloadcms.com/docs) - learn about Payload features and API. -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. - -You can check out [the Payload GitHub repository](https://github.com/payloadcms/payload) as well as [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! - -## Deployment - -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new) from the creators of Next.js. You could also combine this app into a [single Express server](https://github.com/payloadcms/payload/tree/main/examples/custom-server) and deploy in to [Payload Cloud](https://payloadcms.com/new/import). - -Check out our [Payload deployment documentation](https://payloadcms.com/docs/production/deployment) or the [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. - -## Questions - -If you have any issues or questions, reach out to us on [Discord](https://discord.com/invite/payload) or start a [GitHub discussion](https://github.com/payloadcms/payload/discussions). diff --git a/examples/auth/next-app/app/_components/Button/index.tsx b/examples/auth/next-app/app/_components/Button/index.tsx deleted file mode 100644 index eb4e2737b5..0000000000 --- a/examples/auth/next-app/app/_components/Button/index.tsx +++ /dev/null @@ -1,75 +0,0 @@ -'use client' - -import React, { ElementType } from 'react' -import Link from 'next/link' - -import classes from './index.module.scss' - -export type Props = { - label?: string - appearance?: 'default' | 'primary' | 'secondary' - el?: 'button' | 'link' | 'a' - onClick?: () => void - href?: string - newTab?: boolean - className?: string - type?: 'submit' | 'button' - disabled?: boolean - invert?: boolean -} - -export const Button: React.FC = ({ - el: elFromProps = 'link', - label, - newTab, - href, - appearance, - className: classNameFromProps, - onClick, - type = 'button', - disabled, - invert, -}) => { - let el = elFromProps - const newTabProps = newTab ? { target: '_blank', rel: 'noopener noreferrer' } : {} - - const className = [ - classes.button, - classNameFromProps, - classes[`appearance--${appearance}`], - invert && classes[`${appearance}--invert`], - ] - .filter(Boolean) - .join(' ') - - const content = ( -
- {label} -
- ) - - if (onClick || type === 'submit') el = 'button' - - if (el === 'link') { - return ( - - {content} - - ) - } - - const Element: ElementType = el - - return ( - - {content} - - ) -} diff --git a/examples/auth/next-app/app/_components/Gutter/index.tsx b/examples/auth/next-app/app/_components/Gutter/index.tsx deleted file mode 100644 index 3cabc4ac58..0000000000 --- a/examples/auth/next-app/app/_components/Gutter/index.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import React, { forwardRef, Ref } from 'react' - -import classes from './index.module.scss' - -type Props = { - left?: boolean - right?: boolean - className?: string - children: React.ReactNode - ref?: Ref -} - -export const Gutter: React.FC = forwardRef((props, ref) => { - const { left = true, right = true, className, children } = props - - return ( -
- {children} -
- ) -}) - -Gutter.displayName = 'Gutter' diff --git a/examples/auth/next-app/app/_components/Header/Nav/index.tsx b/examples/auth/next-app/app/_components/Header/Nav/index.tsx deleted file mode 100644 index 0015b0ec8a..0000000000 --- a/examples/auth/next-app/app/_components/Header/Nav/index.tsx +++ /dev/null @@ -1,38 +0,0 @@ -'use client' - -import React from 'react' -import Link from 'next/link' - -import { useAuth } from '../../../_providers/Auth' - -import classes from './index.module.scss' - -export const HeaderNav: React.FC = () => { - const { user } = useAuth() - - return ( - - ) -} diff --git a/examples/auth/next-app/app/_components/Header/index.tsx b/examples/auth/next-app/app/_components/Header/index.tsx deleted file mode 100644 index 1642bf4530..0000000000 --- a/examples/auth/next-app/app/_components/Header/index.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import Image from 'next/image' -import Link from 'next/link' -import React from 'react' - -import { Gutter } from '../Gutter' -import classes from './index.module.scss' -import { HeaderNav } from './Nav' - -export function Header() { - return ( -
- - - - - Payload Logo - - - - -
- ) -} - -export default Header diff --git a/examples/auth/next-app/app/_components/Input/index.tsx b/examples/auth/next-app/app/_components/Input/index.tsx deleted file mode 100644 index 771626cf0a..0000000000 --- a/examples/auth/next-app/app/_components/Input/index.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import React from 'react' -import { FieldValues, UseFormRegister, Validate } from 'react-hook-form' - -import classes from './index.module.scss' - -type Props = { - name: string - label: string - register: UseFormRegister - required?: boolean - error: any - type?: 'text' | 'number' | 'password' | 'email' - validate?: (value: string) => boolean | string -} - -export const Input: React.FC = ({ - name, - label, - required, - register, - error, - type = 'text', - validate, -}) => { - return ( -
- - - {error && ( -
- {!error?.message && error?.type === 'required' - ? 'This field is required' - : error?.message} -
- )} -
- ) -} diff --git a/examples/auth/next-app/app/_components/Message/index.tsx b/examples/auth/next-app/app/_components/Message/index.tsx deleted file mode 100644 index 3cd8060868..0000000000 --- a/examples/auth/next-app/app/_components/Message/index.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import React from 'react' - -import classes from './index.module.scss' - -export const Message: React.FC<{ - message?: React.ReactNode - error?: React.ReactNode - success?: React.ReactNode - warning?: React.ReactNode - className?: string -}> = ({ message, error, success, warning, className }) => { - const messageToRender = message || error || success || warning - - if (messageToRender) { - return ( -
- {messageToRender} -
- ) - } - return null -} diff --git a/examples/auth/next-app/app/_components/RenderParams/index.tsx b/examples/auth/next-app/app/_components/RenderParams/index.tsx deleted file mode 100644 index 5c9ce96947..0000000000 --- a/examples/auth/next-app/app/_components/RenderParams/index.tsx +++ /dev/null @@ -1,29 +0,0 @@ -'use client' - -import { useSearchParams } from 'next/navigation' - -import { Message } from '../Message' - -export const RenderParams: React.FC<{ - params?: string[] - message?: string - className?: string -}> = ({ params = ['error', 'message', 'success'], message, className }) => { - const searchParams = useSearchParams() - const paramValues = params.map((param) => searchParams.get(param)).filter(Boolean) - - if (paramValues.length) { - return ( -
- {paramValues.map((paramValue) => ( - - ))} -
- ) - } - - return null -} diff --git a/examples/auth/next-app/app/_components/RichText/index.tsx b/examples/auth/next-app/app/_components/RichText/index.tsx deleted file mode 100644 index 657d2d8d21..0000000000 --- a/examples/auth/next-app/app/_components/RichText/index.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import React from 'react' - -import serialize from './serialize' - -import classes from './index.module.scss' - -const RichText: React.FC<{ className?: string; content: any }> = ({ className, content }) => { - if (!content) { - return null - } - - return ( -
- {serialize(content)} -
- ) -} - -export default RichText diff --git a/examples/auth/next-app/app/_components/RichText/serialize.tsx b/examples/auth/next-app/app/_components/RichText/serialize.tsx deleted file mode 100644 index 1067a9815a..0000000000 --- a/examples/auth/next-app/app/_components/RichText/serialize.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import React, { Fragment } from 'react' -import escapeHTML from 'escape-html' -import { Text } from 'slate' - -// eslint-disable-next-line no-use-before-define -type Children = Leaf[] - -type Leaf = { - type: string - value?: { - url: string - alt: string - } - children: Children - url?: string - [key: string]: unknown -} - -const serialize = (children: Children): React.ReactNode[] => - children.map((node, i) => { - if (Text.isText(node)) { - let text = - - if (node.bold) { - text = {text} - } - - if (node.code) { - text = {text} - } - - if (node.italic) { - text = {text} - } - - if (node.underline) { - text = ( - - {text} - - ) - } - - if (node.strikethrough) { - text = ( - - {text} - - ) - } - - return {text} - } - - if (!node) { - return null - } - - switch (node.type) { - case 'h1': - return

{serialize(node.children)}

- case 'h2': - return

{serialize(node.children)}

- case 'h3': - return

{serialize(node.children)}

- case 'h4': - return

{serialize(node.children)}

- case 'h5': - return
{serialize(node.children)}
- case 'h6': - return
{serialize(node.children)}
- case 'blockquote': - return
{serialize(node.children)}
- case 'ul': - return
    {serialize(node.children)}
- case 'ol': - return
    {serialize(node.children)}
- case 'li': - return
  • {serialize(node.children)}
  • - case 'link': - return ( - - {serialize(node.children)} - - ) - - default: - return

    {serialize(node.children)}

    - } - }) - -export default serialize diff --git a/examples/auth/next-app/app/_providers/Auth/gql.ts b/examples/auth/next-app/app/_providers/Auth/gql.ts deleted file mode 100644 index a12de93c2d..0000000000 --- a/examples/auth/next-app/app/_providers/Auth/gql.ts +++ /dev/null @@ -1,34 +0,0 @@ -export const USER = ` - id - email - firstName - lastName -` - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export const gql = async (query: string): Promise => { - try { - const res = await fetch(`${process.env.NEXT_PUBLIC_PAYLOAD_URL}/api/graphql`, { - method: 'POST', - credentials: 'include', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query, - }), - }) - - const { data, errors } = await res.json() - - if (errors) { - throw new Error(errors[0].message) - } - - if (res.ok && data) { - return data - } - } catch (e: unknown) { - throw new Error(e as string) - } -} diff --git a/examples/auth/next-app/app/_providers/Auth/index.tsx b/examples/auth/next-app/app/_providers/Auth/index.tsx deleted file mode 100644 index 4ba00feea8..0000000000 --- a/examples/auth/next-app/app/_providers/Auth/index.tsx +++ /dev/null @@ -1,180 +0,0 @@ -'use client' - -import React, { createContext, useCallback, useContext, useEffect, useState } from 'react' - -import { User } from '../../payload-types' -import { gql, USER } from './gql' -import { rest } from './rest' -import { AuthContext, Create, ForgotPassword, Login, Logout, ResetPassword } from './types' - -const Context = createContext({} as AuthContext) - -export const AuthProvider: React.FC<{ children: React.ReactNode; api?: 'rest' | 'gql' }> = ({ - children, - api = 'rest', -}) => { - const [user, setUser] = useState() - - const create = useCallback( - async (args) => { - if (api === 'rest') { - const user = await rest(`${process.env.NEXT_PUBLIC_PAYLOAD_URL}/api/users`, args) - setUser(user) - return user - } - - if (api === 'gql') { - const { createUser: user } = await gql(`mutation { - createUser(data: { email: "${args.email}", password: "${args.password}", firstName: "${args.firstName}", lastName: "${args.lastName}" }) { - ${USER} - } - }`) - - setUser(user) - return user - } - }, - [api], - ) - - const login = useCallback( - async (args) => { - if (api === 'rest') { - const user = await rest(`${process.env.NEXT_PUBLIC_PAYLOAD_URL}/api/users/login`, args) - setUser(user) - return user - } - - if (api === 'gql') { - const { loginUser } = await gql(`mutation { - loginUser(email: "${args.email}", password: "${args.password}") { - user { - ${USER} - } - exp - } - }`) - - setUser(loginUser?.user) - return loginUser?.user - } - }, - [api], - ) - - const logout = useCallback(async () => { - if (api === 'rest') { - await rest(`${process.env.NEXT_PUBLIC_PAYLOAD_URL}/api/users/logout`) - setUser(null) - return - } - - if (api === 'gql') { - await gql(`mutation { - logoutUser - }`) - - setUser(null) - } - }, [api]) - - // On mount, get user and set - useEffect(() => { - const fetchMe = async () => { - if (api === 'rest') { - const user = await rest( - `${process.env.NEXT_PUBLIC_PAYLOAD_URL}/api/users/me`, - {}, - { - method: 'GET', - }, - ) - setUser(user) - } - - if (api === 'gql') { - const { meUser } = await gql(`query { - meUser { - user { - ${USER} - } - exp - } - }`) - - setUser(meUser.user) - } - } - - fetchMe() - }, [api]) - - const forgotPassword = useCallback( - async (args) => { - if (api === 'rest') { - const user = await rest( - `${process.env.NEXT_PUBLIC_PAYLOAD_URL}/api/users/forgot-password`, - args, - ) - setUser(user) - return user - } - - if (api === 'gql') { - const { forgotPasswordUser } = await gql(`mutation { - forgotPasswordUser(email: "${args.email}") - }`) - - return forgotPasswordUser - } - }, - [api], - ) - - const resetPassword = useCallback( - async (args) => { - if (api === 'rest') { - const user = await rest( - `${process.env.NEXT_PUBLIC_PAYLOAD_URL}/api/users/reset-password`, - args, - ) - setUser(user) - return user - } - - if (api === 'gql') { - const { resetPasswordUser } = await gql(`mutation { - resetPasswordUser(password: "${args.password}", token: "${args.token}") { - user { - ${USER} - } - } - }`) - - setUser(resetPasswordUser.user) - return resetPasswordUser.user - } - }, - [api], - ) - - return ( - - {children} - - ) -} - -type UseAuth = () => AuthContext // eslint-disable-line no-unused-vars - -export const useAuth: UseAuth = () => useContext(Context) diff --git a/examples/auth/next-app/app/_providers/Auth/rest.ts b/examples/auth/next-app/app/_providers/Auth/rest.ts deleted file mode 100644 index 0d6fd3c2dc..0000000000 --- a/examples/auth/next-app/app/_providers/Auth/rest.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { User } from '../../payload-types' - -export const rest = async ( - url: string, - args?: any, // eslint-disable-line @typescript-eslint/no-explicit-any - options?: RequestInit, -): Promise => { - const method = options?.method || 'POST' - - try { - const res = await fetch(url, { - method, - ...(method === 'POST' ? { body: JSON.stringify(args) } : {}), - credentials: 'include', - headers: { - 'Content-Type': 'application/json', - ...options?.headers, - }, - ...options, - }) - - const { errors, user } = await res.json() - - if (errors) { - throw new Error(errors[0].message) - } - - if (res.ok) { - return user - } - } catch (e: unknown) { - throw new Error(e as string) - } -} diff --git a/examples/auth/next-app/app/_providers/Auth/types.ts b/examples/auth/next-app/app/_providers/Auth/types.ts deleted file mode 100644 index 7911d6a4f3..0000000000 --- a/examples/auth/next-app/app/_providers/Auth/types.ts +++ /dev/null @@ -1,31 +0,0 @@ -import type { User } from '../../payload-types' - -// eslint-disable-next-line no-unused-vars -export type ResetPassword = (args: { - password: string - passwordConfirm: string - token: string -}) => Promise - -export type ForgotPassword = (args: { email: string }) => Promise // eslint-disable-line no-unused-vars - -export type Create = (args: { - email: string - password: string - firstName: string - lastName: string -}) => Promise // eslint-disable-line no-unused-vars - -export type Login = (args: { email: string; password: string }) => Promise // eslint-disable-line no-unused-vars - -export type Logout = () => Promise - -export interface AuthContext { - user?: User | null - setUser: (user: User | null) => void // eslint-disable-line no-unused-vars - logout: Logout - login: Login - create: Create - resetPassword: ResetPassword - forgotPassword: ForgotPassword -} diff --git a/examples/auth/next-app/app/_utilities/getMeUser.ts b/examples/auth/next-app/app/_utilities/getMeUser.ts deleted file mode 100644 index b774f15ccc..0000000000 --- a/examples/auth/next-app/app/_utilities/getMeUser.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { cookies } from 'next/headers' -import { redirect } from 'next/navigation' - -import type { User } from '../payload-types' - -export const getMeUser = async (args?: { - nullUserRedirect?: string - validUserRedirect?: string -}): Promise<{ - user: User - token: string | undefined -}> => { - const { nullUserRedirect, validUserRedirect } = args || {} - const cookieStore = cookies() - const token = cookieStore.get('payload-token')?.value - - const meUserReq = await fetch(`${process.env.NEXT_PUBLIC_PAYLOAD_URL}/api/users/me`, { - headers: { - Authorization: `JWT ${token}`, - }, - }) - - const { - user, - }: { - user: User - } = await meUserReq.json() - - if (validUserRedirect && meUserReq.ok && user) { - redirect(validUserRedirect) - } - - if (nullUserRedirect && (!meUserReq.ok || !user)) { - redirect(nullUserRedirect) - } - - return { - user, - token, - } -} diff --git a/examples/auth/next-app/app/account/AccountForm/index.tsx b/examples/auth/next-app/app/account/AccountForm/index.tsx deleted file mode 100644 index 7c8c04bafd..0000000000 --- a/examples/auth/next-app/app/account/AccountForm/index.tsx +++ /dev/null @@ -1,155 +0,0 @@ -'use client' - -import React, { Fragment, useCallback, useEffect, useRef, useState } from 'react' -import { useForm } from 'react-hook-form' -import { useRouter } from 'next/navigation' - -import { Button } from '../../_components/Button' -import { Input } from '../../_components/Input' -import { Message } from '../../_components/Message' -import { useAuth } from '../../_providers/Auth' - -import classes from './index.module.scss' - -type FormData = { - email: string - name: string - password: string - passwordConfirm: string -} - -export const AccountForm: React.FC = () => { - const [error, setError] = useState('') - const [success, setSuccess] = useState('') - const { user, setUser } = useAuth() - const [changePassword, setChangePassword] = useState(false) - const router = useRouter() - - const { - register, - handleSubmit, - formState: { errors, isLoading }, - reset, - watch, - } = useForm() - - const password = useRef({}) - password.current = watch('password', '') - - const onSubmit = useCallback( - async (data: FormData) => { - if (user) { - const response = await fetch( - `${process.env.NEXT_PUBLIC_PAYLOAD_URL}/api/users/${user.id}`, - { - // Make sure to include cookies with fetch - credentials: 'include', - method: 'PATCH', - body: JSON.stringify(data), - headers: { - 'Content-Type': 'application/json', - }, - }, - ) - - if (response.ok) { - const json = await response.json() - setUser(json.doc) - setSuccess('Successfully updated account.') - setError('') - setChangePassword(false) - reset({ - email: json.doc.email, - name: json.doc.name, - password: '', - passwordConfirm: '', - }) - } else { - setError('There was a problem updating your account.') - } - } - }, - [user, setUser, reset], - ) - - useEffect(() => { - if (user === null) { - router.push(`/login?unauthorized=account`) - } - - // Once user is loaded, reset form to have default values - if (user) { - reset({ - email: user.email, - password: '', - passwordConfirm: '', - }) - } - }, [user, router, reset, changePassword]) - - return ( -
    - - {!changePassword ? ( - -

    - {'To change your password, '} - - . -

    - -
    - ) : ( - -

    - {'Change your password below, or '} - - . -

    - - value === password.current || 'The passwords do not match'} - error={errors.passwordConfirm} - /> -
    - )} - - {' to change your password.'} -

    - - - ) : ( - -

    - {'Change your password below, or '} - - . -

    - - value === password.current || 'The passwords do not match'} - error={errors.passwordConfirm} - /> -
    - )} -