diff --git a/convex/auth.config.ts b/convex/auth.config.ts new file mode 100644 index 0000000..5dfead8 --- /dev/null +++ b/convex/auth.config.ts @@ -0,0 +1,8 @@ +export default { + providors: [ + { + domain: process.env.NEXT_PUBLIC_CLERK_FRONTEND_API_URL, + applicationId: process.env.NEXTAUTH_ID, + } + ] +} \ No newline at end of file diff --git a/src/app/layout.tsx b/src/app/layout.tsx index f7fa87e..8850714 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,6 +1,8 @@ import type { Metadata } from "next"; import { Geist, Geist_Mono } from "next/font/google"; import "./globals.css"; +import { ClerkProvider } from "@clerk/nextjs"; +import ConvexClientProvider from "@/providors/ConvexClientProvider"; const geistSans = Geist({ variable: "--font-geist-sans", @@ -23,12 +25,16 @@ export default function RootLayout({ children: React.ReactNode; }>) { return ( - - - {children} - - + + + + + {children} + + + + ); } diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 0000000..6811139 --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1,18 @@ +import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server' + +const isPublicRoute = createRouteMatcher(['/']) + +export default clerkMiddleware(async ( auth, req ) => { + if (!isPublicRoute(req)) { + await auth.protect() + } +}) + +export const config = { + matcher: [ + // Skip Next.js internals and all static files, unless found in search params + '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', + // Always run for API routes + '/(api|trpc)(.*)', + ], +} \ No newline at end of file diff --git a/src/providors/ConvexClientProvider.tsx b/src/providors/ConvexClientProvider.tsx new file mode 100644 index 0000000..98dc7b2 --- /dev/null +++ b/src/providors/ConvexClientProvider.tsx @@ -0,0 +1,22 @@ +"use client" + +'use client' + +import { ReactNode } from 'react' +import { ConvexReactClient } from 'convex/react' +import { ConvexProviderWithClerk } from 'convex/react-clerk' +import { useAuth } from '@clerk/nextjs' + +if (!process.env.NEXT_PUBLIC_CONVEX_URL) { + throw new Error('Missing NEXT_PUBLIC_CONVEX_URL in your .env file') +} + +const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL) + +export default function ConvexClientProvider({ children }: { children: ReactNode }) { + return ( + + {children} + + ) +} \ No newline at end of file