{"id":24737963,"url":"https://github.com/DanailMinchev/payload-clerk-example","last_synced_at":"2025-10-10T06:32:12.784Z","repository":{"id":272720743,"uuid":"915773284","full_name":"DanailMinchev/payload-clerk-example","owner":"DanailMinchev","description":"Payload CMS and Clerk example","archived":false,"fork":false,"pushed_at":"2025-04-05T11:42:18.000Z","size":912,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T23:36:59.342Z","etag":null,"topics":["clerk","clerkjs","payload","payload-template","payloadcms"],"latest_commit_sha":null,"homepage":"https://www.youtube.com/watch?v=egKaeOuddFA","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanailMinchev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-12T19:01:40.000Z","updated_at":"2025-04-05T13:55:34.000Z","dependencies_parsed_at":"2025-01-16T08:44:59.917Z","dependency_job_id":"d9242131-f401-4f25-a508-bb898fb397fb","html_url":"https://github.com/DanailMinchev/payload-clerk-example","commit_stats":null,"previous_names":["danailminchev/payload-clerk-example"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/DanailMinchev/payload-clerk-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanailMinchev%2Fpayload-clerk-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanailMinchev%2Fpayload-clerk-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanailMinchev%2Fpayload-clerk-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanailMinchev%2Fpayload-clerk-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanailMinchev","download_url":"https://codeload.github.com/DanailMinchev/payload-clerk-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanailMinchev%2Fpayload-clerk-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002966,"owners_count":26083489,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clerk","clerkjs","payload","payload-template","payloadcms"],"created_at":"2025-01-27T22:34:46.489Z","updated_at":"2025-10-10T06:32:12.776Z","avatar_url":"https://github.com/DanailMinchev.png","language":"TypeScript","funding_links":[],"categories":["Education"],"sub_categories":["Examples"],"readme":"## Payload and Clerk example\n\nThis is an example for Payload CMS and Clerk integration.\n\n## Contents\n\n- [YouTube videos](#youtube-videos)\n- [Getting Started](#getting-started)\n- [Webhooks](#webhooks)\n- [E2E Testing](#e2e-testing)\n\n## YouTube videos\n\n**Part 2 - Advanced integration**\n\n[![Payload CMS and Clerk - advanced integration](https://img.youtube.com/vi/egKaeOuddFA/0.jpg)](https://www.youtube.com/watch?v=egKaeOuddFA)\n\n[https://www.youtube.com/watch?v=egKaeOuddFA](https://www.youtube.com/watch?v=egKaeOuddFA)\n\nSource code for the video is in the `part-2` branch: https://github.com/DanailMinchev/payload-clerk-example/tree/feat/part-2\n\n**Part 1 - Basic integration**\n\n[![Payload and Clerk example](https://img.youtube.com/vi/7PNGNqqFlu0/0.jpg)](https://www.youtube.com/watch?v=7PNGNqqFlu0)\n\n[https://www.youtube.com/watch?v=7PNGNqqFlu0](https://www.youtube.com/watch?v=7PNGNqqFlu0)\n\nSource code for the video is in the `part-1` branch: https://github.com/DanailMinchev/payload-clerk-example/tree/feat/part-1\n\n## Getting Started\n\nInstall dependencies:\n\n```shell\nnpm ci\n```\n\n1. Create a new Clerk application and configure:\n\nEnable `Email` as `Sign in option`.\n\nThe setup is described in details in the videos above, but here are the settings for reference:\n\n- [Test mode](https://clerk.com/docs/testing/test-emails-and-phones#setup-test-mode)\n\n  ![Test mode](./docs/assets/test-mode.png)\n\n- [publicMetadata](https://clerk.com/docs/references/nextjs/basic-rbac)\n\n  ![publicMetadata](./docs/assets/public-metadata.png)\n\n```json\n{\n  \"metadata\": \"{{user.public_metadata}}\"\n}\n```\n\n2. Copy the `env.example` file into `.env.local` file.\n\n3. Set Clerk environment variables [documentation](https://clerk.com/docs/deployments/clerk-environment-variables):\n\n`NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY`\n\nYour Clerk app's Publishable Key, which you can find in the Clerk Dashboard. It will be prefixed with pk*test* in\ndevelopment instances and pk*live* in production instances.\n\n`CLERK_SECRET_KEY`\n\nYour Clerk app's Secret Key, which you can find in the Clerk Dashboard. It will be prefixed with sk*test* in development\ninstances and sk*live* in production instances. Do not expose this on the frontend with a public environment variable.\n\n`SIGNING_SECRET`\n\nIn case you are going to use [Webhooks](https://clerk.com/docs/webhooks/sync-data), you will need to set Signing Secret.\n\n4. Set Payload environment variables [documentation](https://payloadcms.com/docs/getting-started/installation)\n\n`PAYLOAD_SECRET`\n\nThis environmental variable acts as your secret key. It's paramount that you ensure its value is both secure and strong,\nas it's integral to the encryption and decryption process.\n\n`DATABASE_URI`\n\nThis is the database connection string. Uncomment `DATABASE_URI` for `SQLite` or `PostgreSQL`.\n\n5. If you selected the `PostgreSQL` you can use Docker:\n\n```shell\ndocker compose up\n```\n\nand edit the `src/payload.config.ts` file:\n\nUncomment:\n\n```typescript\nimport { postgresAdapter } from \"@payloadcms/db-postgres\";\n```\n\nComment / delete:\n\n```typescript\nimport { sqliteAdapter } from \"@payloadcms/db-sqlite\";\n```\n\nUncomment:\n\n```typescript\n  // PostgreSQL\ndb: postgresAdapter({\n  pool: {\n    connectionString: process.env.DATABASE_URI || \"\",\n  },\n}),\n```\n\nComment / delete:\n\n```typescript\n  // SQLite\ndb: sqliteAdapter({\n  client: {\n    url: process.env.DATABASE_URI || \"\",\n  },\n}),\n```\n\n6. For testing and local development purposes following users are being used:\n\n- all-roles-1+clerk_test@example.com\n- super-admin-1+clerk_test@example.com\n- admin-1+clerk_test@example.com\n- editor-1+clerk_test@example.com\n- user-1+clerk_test@example.com\n\nPlease set the environment variables accordingly with their passwords in your `.env.local` file:\n\n```dotenv\nE2E_CLERK_ALL_ROLES_USER_EMAIL=all-roles-1+clerk_test@example.com\nE2E_CLERK_ALL_ROLES_USER_PASSWORD=\nE2E_CLERK_ALL_ROLES_USER_PHONE=+19735550101\n\nE2E_CLERK_SUPER_ADMIN_USER_EMAIL=super-admin-1+clerk_test@example.com\nE2E_CLERK_SUPER_ADMIN_USER_PASSWORD=\nE2E_CLERK_SUPER_ADMIN_USER_PHONE=+19735550102\n\nE2E_CLERK_ADMIN_USER_EMAIL=admin-1+clerk_test@example.com\nE2E_CLERK_ADMIN_USER_PASSWORD=\nE2E_CLERK_ADMIN_USER_PHONE=+19735550103\n\nE2E_CLERK_EDITOR_USER_EMAIL=editor-1+clerk_test@example.com\nE2E_CLERK_EDITOR_USER_PASSWORD=\nE2E_CLERK_EDITOR_USER_PHONE=+19735550104\n\nE2E_CLERK_AUTHENTICATED_USER_EMAIL=user-1+clerk_test@example.com\nE2E_CLERK_AUTHENTICATED_USER_PASSWORD=\nE2E_CLERK_AUTHENTICATED_USER_PHONE=+19735550105\n```\n\nThe above users are using test emails and test phone numbers as described in [Test emails and phones](https://clerk.com/docs/testing/test-emails-and-phones).\n\nIf you want to use phone numbers, you need to enable \"Phone number\" in the Clerk's dashboard, otherwise seed endpoint will not work.\n\n![Phone number](./docs/assets/phone-number.png)\n\nOtherwise, leave the `E2E_CLERK_*_USER_PHONE` environment variables empty.\n\n7. Register the `E2E` users.\n\nYou can register the `E2E` users from the above point manually or automatically using the `GET /api/app/seed` endpoint.\n\nRun the application: `npm run dev`\n\n**Registering automatically**\n\nInvoke / navigate to [http://localhost:3000/api/app/seed](http://localhost:3000/api/app/seed) endpoint.\n\nObserve the console for logs.\n\n**WARNING: the endpoint will delete your existing data**\n\n**Registering manually**\n\nYou should register your `super-admin-1+clerk_test@example.com` user in Clerk manually and set the `super-admin` role.\n\nThe `super-admin-1+clerk_test@example.com` user should have following [public metadata](https://clerk.com/docs/users/metadata#public-metadata):\n\n```json\n{\n  \"roles\": [\"super-admin\"]\n}\n```\n\nand you should set the rest of the user roles via the [admin dashboard](http://localhost:3000/admin/clerk-users) as follows:\n\n- all-roles-1+clerk_test@example.com (super-admin role, admin role, editor role)\n- admin-1+clerk_test@example.com (admin role)\n- editor-1+clerk_test@example.com (editor role)\n- user-1+clerk_test@example.com (no role, no changes to user's metadata, used for simulating a website user / registered\n  user)\n\n8. Run the development server (if not running already):\n\n```shell\nnpm run dev\n```\n\nOpen [http://localhost:3000](http://localhost:3000) with your browser to see the result.\n\n## Webhooks\n\nPlease refer to the official documentation - [Sync Clerk data to your app with webhooks](https://clerk.com/docs/webhooks/sync-data).\n\nThe app exposes `POST /api/clerk/webhooks` endpoint which can be configured in\nthe [Clerk Dashboard](https://dashboard.clerk.com/last-active?path=webhooks).\n\nEnvironment variables:\n\n- `SIGNING_SECRET` : \"Signing Secret\" from the [Clerk Dashboard](https://dashboard.clerk.com/last-active?path=webhooks).\n\nCurrently, the webhooks endpoint is listening on the following events:\n\n- `user.created`\n- `user.updated`\n- `user.deleted`\n\n### Testing webhooks with ngrok\n\nPlease follow the official documentation - [Setup \u0026 Installation](https://dashboard.ngrok.com/get-started/setup)\n\nTo run ngrok in Docker (macOS):\n\n```shell\ndocker run -it -e NGROK_AUTHTOKEN={NGROK_AUTHTOKEN} ngrok/ngrok:latest http host.docker.internal:3000 --url={NGROK_DOMAIN}\n```\n\nTo run ngrok in Docker (other OS):\n\n```shell\ndocker run -it -e NGROK_AUTHTOKEN={NGROK_AUTHTOKEN} ngrok/ngrok:latest http 3000 --url={NGROK_DOMAIN}\n```\n\nTo run ngrok using native binary:\n\n```shell\nngrok http 3000 --url={NGROK_DOMAIN}\n```\n\nReplace `{NGROK_AUTHTOKEN}` with [your authtoken](https://dashboard.ngrok.com/get-started/your-authtoken).\n\nReplace `{NGROK_DOMAIN}` with [your free static domain](https://dashboard.ngrok.com/domains),\nfor example: `your-static-domain-here.ngrok-free.app`.\n\n## E2E Testing\n\nThere are E2E tests implemented using [Playwright](https://playwright.dev/).\n\nThey are devided into two categories\n\n- api-tests\n  Used to verify the access control.\n- app-tests\n  Used to verify the app pages, including those behind authentication.\n\nBefore running the tests, you should install dependencies by executing:\n\n```shell\nnpx playwright install\nnpx playwright install-deps\n```\n\nThen you can use following scripts:\n\n- For UI mode:\n  ```shell\n  npm run playwright:test:ui\n  ```\n- For command line mode with debugging:\n\n  ```shell\n  npm run playwright:test:debug\n  ```\n\n- For command line mode (used for CI):\n  ```shell\n  npm run playwright:test\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDanailMinchev%2Fpayload-clerk-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDanailMinchev%2Fpayload-clerk-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDanailMinchev%2Fpayload-clerk-example/lists"}