diff --git a/README.md b/README.md
index 63ed8969..df09c3f8 100644
--- a/README.md
+++ b/README.md
@@ -7,9 +7,9 @@
- [x] Playwright E2E tests.
- [x] github actions.
- [x] SEO (dub.co is a great reference) for example robots.ts file.
+- [x] tRPC api with tanstack query.
- [ ] Shadcn UI.
- [ ] Slate/Plate.js editor.
-- [ ] tRPC api with tanstack query.
- [ ] New & Refined README.md.
- [ ] Add a `CONTRIBUTING.md` file.
@@ -18,7 +18,6 @@
- [x] Neon Database / Drizzle orm.
- [x] Upstash redis
- [x] Clerk authentication.
-- [ ] Arcjet.
- [ ] Resend & React email.
- [ ] Stripe payment.
- [ ] Sentry.
diff --git a/bun.lockb b/bun.lockb
index 529f0bd1..132832e5 100755
Binary files a/bun.lockb and b/bun.lockb differ
diff --git a/cspell.config.yaml b/cspell.config.yaml
index 1c127a56..b1c0aa2a 100644
--- a/cspell.config.yaml
+++ b/cspell.config.yaml
@@ -36,6 +36,8 @@ words:
- Shadcn
- Signin
- Signup
+ - sslmode
+ - superjson
- tailwindcss
- tanstack
- trpc
@@ -44,4 +46,3 @@ words:
- typecheck
- Uploadthing
- Upstash
- - sslmode
diff --git a/package.json b/package.json
index 349cc34f..ce4bdced 100644
--- a/package.json
+++ b/package.json
@@ -60,6 +60,10 @@
"@radix-ui/react-navigation-menu": "^1.1.4",
"@radix-ui/react-slot": "^1.0.2",
"@t3-oss/env-nextjs": "^0.10.1",
+ "@tanstack/react-query": "^5.39.0",
+ "@trpc/client": "^11.0.0-rc.374",
+ "@trpc/react-query": "^11.0.0-rc.374",
+ "@trpc/server": "^11.0.0-rc.374",
"@upstash/redis": "^1.31.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
@@ -72,6 +76,8 @@
"next-themes": "^0.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
+ "server-only": "^0.0.1",
+ "superjson": "^2.2.1",
"tailwind-merge": "^2.3.0",
"zod": "^3.23.8"
},
diff --git a/src/app/(dashboard)/app/page.tsx b/src/app/(dashboard)/app/page.tsx
index ba313f76..37145999 100644
--- a/src/app/(dashboard)/app/page.tsx
+++ b/src/app/(dashboard)/app/page.tsx
@@ -1,14 +1,18 @@
+import { api } from '@/lib/trpc/server';
import { SignOutButton } from '@clerk/nextjs';
/**
* This is the main page for the dashboard.
* @returns A Next.js RSC page component.
*/
-export default function DashboardHome() {
+export default async function DashboardHome() {
+ const { message } = await api.greeting.protected();
+
return (
Hello World
+ {message}
);
}
diff --git a/src/app/api/trpc/[trpc]/route.ts b/src/app/api/trpc/[trpc]/route.ts
new file mode 100644
index 00000000..71570b8d
--- /dev/null
+++ b/src/app/api/trpc/[trpc]/route.ts
@@ -0,0 +1,29 @@
+import type { NextRequest } from 'next/server';
+
+import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
+
+import { env } from '@/env';
+import { appRouter } from '@/server';
+import { createTRPCContext } from '@/server/trpc';
+
+const createContext = async (req: NextRequest) => {
+ return createTRPCContext({
+ headers: req.headers,
+ });
+};
+
+const handler = (req: NextRequest) =>
+ fetchRequestHandler({
+ endpoint: '/api/trpc',
+ req,
+ router: appRouter,
+ createContext: () => createContext(req),
+ onError: ({ path, error }) => {
+ env.NODE_ENV === 'development' &&
+ console.error(
+ `❌ tRPC failed on ${path ?? ''}: ${error.message}`,
+ );
+ },
+ });
+
+export { handler as GET, handler as POST };
diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index 13a9f52d..9c76917c 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -12,6 +12,7 @@ import { ThemeProvider } from 'next-themes';
import type { PropsWithChildren } from 'react';
import { constructMetadata } from '@/lib/utils';
+import { TRPCReactProvider } from '@/lib/trpc/react';
export const metadata: Metadata = constructMetadata();
@@ -34,7 +35,7 @@ export default function RootLayout({ children }: PropsWithChildren) {
>
- {children}
+ {children}