Luc7mo ago

Integrating tRPC with Clerk Authentication in an Existing Next.js "Turborepo" Project

Hello, I am currently working on a Next.js application within a Turborepo setup and am looking to integrate tRPC for efficient type-safe API calls. My project consists of multiple apps, including DOCS and WEB, and I aim to establish a shared authentication mechanism across these apps using Clerk authentication with tRPC. I have a couple of questions regarding this integration: 1. Documentation for tRPC Integration in Next.js Turborepo: Could someone guide me to comprehensive documentation or resources on adding tRPC to an existing Next.js project within a Turborepo environment? I am particularly interested in best practices for setting up tRPC in a multi-app repository to ensure smooth interoperability and maintainability. 2. Implementing Clerk Authentication with tRPC: Once tRPC is integrated, I plan to implement Clerk for user authentication. Does anyone have experience or examples of using Clerk with tRPC in a similar setup? I am looking for insights or code snippets on how to effectively configure Clerk authentication in a Turborepo project with tRPC, ensuring seamless authentication flow across different apps in the repository. Any advice, examples, or pointers towards relevant resources would be greatly appreciated. I'm particularly interested in how to structure the tRPC and Clerk integration to maintain a clean and efficient codebase, following best practices for a scalable and maintainable architecture. Cheers.
1 Reply
Krishna7mo ago
tRPC handles authentication at routes level with a middleware & hence is not married to any specific auth system. You can check an implementation here. Check the isAuthed & isTeziAdmin middlewares here.
subs-manager/apps/api/src/trpc/index.ts at main · krishna-404/subs-...
Subscriptions manager tool. Contribute to krishna-404/subs-manager development by creating an account on GitHub.