{"id":28894948,"url":"https://github.com/cipherstash/protect-example-nextjs-14-supabase","last_synced_at":"2025-09-20T08:54:40.950Z","repository":{"id":293498885,"uuid":"984241687","full_name":"cipherstash/protect-example-nextjs-14-supabase","owner":"cipherstash","description":"Next.js 14 (Pages Router) with Protect.js and Supabase Example","archived":false,"fork":false,"pushed_at":"2025-05-23T15:49:01.000Z","size":186,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-23T17:02:26.530Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/cipherstash.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-05-15T16:00:59.000Z","updated_at":"2025-05-23T15:49:05.000Z","dependencies_parsed_at":"2025-05-15T17:23:28.205Z","dependency_job_id":"a3317f73-5151-4340-bb6c-f76d81913d0b","html_url":"https://github.com/cipherstash/protect-example-nextjs-14-supabase","commit_stats":null,"previous_names":["cipherstash/protect-example-nextjs-14-supabase"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cipherstash/protect-example-nextjs-14-supabase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Fprotect-example-nextjs-14-supabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Fprotect-example-nextjs-14-supabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Fprotect-example-nextjs-14-supabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Fprotect-example-nextjs-14-supabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cipherstash","download_url":"https://codeload.github.com/cipherstash/protect-example-nextjs-14-supabase/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Fprotect-example-nextjs-14-supabase/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261060325,"owners_count":23103992,"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","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":[],"created_at":"2025-06-21T04:15:34.926Z","updated_at":"2025-09-20T08:54:40.932Z","avatar_url":"https://github.com/cipherstash.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Next.js 14 (Pages Router) with Protect.js and Supabase Example\n\nThis is an example application that demonstrates how to use [CipherStash Protect.js](https://github.com/cipherstash/protectjs) for data protection in a Next.js 14.x application, which uses the `pages` router, and a Supabase integration. The application showcases how to encrypt sensitive data before storing it in Supabase and decrypt it when retrieving.\n\n## Features\n\n- Next.js 14 with Pages Router\n- CipherStash Protect.js for data encryption/decryption\n- Supabase JS SDK for database operations\n- TypeScript support\n- TailwindCSS for styling\n- Zod for runtime type validation\n\n## Key Implementation Details\n\n### Data Protection\n\nThe application uses Protect.js to encrypt sensitive user data (email addresses) before storing them in Supabase. The encryption/decryption process happens on the server side to ensure security. Key features include:\n\n- Server-side decryption using `getServerSideProps`\n- Type-safe data handling with Zod schemas\n- Bulk decryption of encrypted data\n- Secure API routes for data insertion\n\n### Implementation Requirements\n\nWhen implementing Protect.js in your own application, there are several key requirements to note:\n\n1. **Server-Side Data Handling**\n\n   - All encryption/decryption must be performed server-side\n   - Use `getServerSideProps` for fetching and decrypting data ([example in `src/pages/index.tsx`](src/pages/index.tsx))\n   - Create API routes for handling data insertion with encryption ([example in `src/pages/api/users.ts`](src/pages/api/users.ts))\n\n2. **Type Safety**\n\n   - Implement Zod schemas to validate encrypted and decrypted data ([example in `src/lib/data.ts`](src/lib/data.ts))\n   - Define separate schemas for encrypted and decrypted data structures\n   - Use TypeScript types to ensure type safety throughout the application\n\n3. **Database Integration**\n\n   - Store both plaintext and encrypted versions of sensitive data\n   - Use bulk decryption for efficient data retrieval ([example in `src/lib/data.ts`](src/lib/data.ts))\n   - Implement proper error handling for encryption/decryption operations\n\n4. **Security Best Practices**\n   - Never expose encryption/decryption logic to the client\n   - Use API routes for all data modification operations ([example in `src/pages/api/users.ts`](src/pages/api/users.ts))\n   - Implement proper error handling and validation\n\n### Database Integration\n\nThe application uses Supabase as its database backend:\n\n- Secure data storage with encrypted fields\n- Type-safe database operations\n\n## Getting Started\n\n1. Clone the repository\n2. Install dependencies:\n   ```bash\n   npm install\n   ```\n3. Set up your environment variables:\n   ```env\n   NEXT_PUBLIC_SUPABASE_URL=\n   NEXT_PUBLIC_SUPABASE_ANON_KEY=\n   CS_CLIENT_ID=\n   CS_CLIENT_KEY=\n   CS_CLIENT_ACCESS_KEY=\n   CS_WORKSPACE_CRN=\n   ```\n4. Run the development server:\n   ```bash\n   npm run dev\n   ```\n\n## Project Structure\n\n- `/src/pages` - Next.js pages and API routes\n- `/src/lib` - Utility functions and database operations\n- `/src/protect` - Protect.js configuration\n\n## Security Considerations\n\n- All encryption/decryption operations are performed server-side\n- Sensitive data is never exposed to unauthenticated clients in plaintext\n- API routes are used to handle data insertion with encryption\n- Type validation ensures data integrity\n\n## Learn More\n\n- [CipherStash Protect.js Documentation](https://github.com/cipherstash/protectjs)\n- [Next.js Documentation](https://nextjs.org/docs)\n- [Supabase Documentation](https://supabase.com/docs)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcipherstash%2Fprotect-example-nextjs-14-supabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcipherstash%2Fprotect-example-nextjs-14-supabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcipherstash%2Fprotect-example-nextjs-14-supabase/lists"}