This project is a real-time chat application built with Next.js, using Clerk for authentication and Convex for real-time data synchronization. Currently, the project has implemented basic authentication and data storage.
-
Install Next.js and Set Up the Project
npx create-next-app@latest your-project-name cd your-project-name -
Install Clerk and Convex
npm install @clerk/nextjs @clerk/clerk-react convex # or yarn add @clerk/nextjs @clerk/clerk-react convex -
Create Projects in Clerk and Convex
-
Set Up Environment Variables Create a
.env.localfile in the root of your project and add the following variables:CONVEX_DEPLOYMENT= NEXT_PUBLIC_CONVEX_URL= NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY= CLERK_SECRET_KEY= CLERK_WEBHOOK_SECRET= CONVEX_DEPLOY_KEY=Refer to
.env.examplefor any additional required variables. -
Set Up Clerk Webhook In your Clerk dashboard, set up a webhook with the Convex URL in this format:
https://your-project-domain.convex.site/clerk-users-webhookReplace
your-project-domainwith your actual Convex project domain. -
Create JWT Template in Clerk
- In Clerk, create a JWT template of type "Convex"
- Copy the issuer URL
-
Configure Convex Authentication Create a file named
auth.config.tsin theconvexfolder of your project:export default { providers: [ { domain: "https://your-clerk-issuer-url", applicationID: "convex", }, ], };
Replace
https://your-clerk-issuer-urlwith the issuer URL you copied from Clerk. -
Set Environment Variable in Convex Project In your Convex project settings, add the following environment variable:
CLERK_WEBHOOK_SECRET=your_webhook_secret
After completing the setup steps, you can run the project using:
npm run dev
# or
yarn devOpen http://localhost:3000 in your browser to see the result.
At this point, the project has:
- Basic authentication implemented using Clerk
- Initial setup for storing data in Convex
- Basic project structure and routing
Next steps will involve implementing the chat functionality and real-time updates.
For more detailed information on configuring Clerk and Convex, please refer to their respective documentation:
npx convex deploy --cmd 'npm run build'