### Manual Project Setup: Install Dependencies Source: https://github.com/get-convex/v1/blob/main/README.md This command installs all necessary project dependencies using `bun install`. ```bash bun install ``` -------------------------------- ### Manual Project Setup: Start Development Server Source: https://github.com/get-convex/v1/blob/main/README.md This command starts all components of the application (web, app, API, email) in development mode. ```bash bun dev ``` -------------------------------- ### Manual Project Setup: Configure Convex Authentication Source: https://github.com/get-convex/v1/blob/main/README.md This command initiates the Convex authentication setup process, guiding the user through prompts to configure authentication for the project. ```bash npx @convex-dev/auth ``` -------------------------------- ### Manual Project Setup: Configure Convex Backend Source: https://github.com/get-convex/v1/blob/main/README.md Navigate to the backend package and run the setup script to create a new Convex project. This step is expected to fail after project creation due to missing environment variables, which will be addressed later. ```bash cd packages/backend npm run setup ``` -------------------------------- ### Manual Project Setup: Start Specific Development Servers Source: https://github.com/get-convex/v1/blob/main/README.md These commands allow starting individual components of the application in development mode, such as the web app, mobile app, Convex API, or email app. ```bash bun dev:web bun dev:app bun dev:convex bun dev:email ``` -------------------------------- ### Manual Project Setup: Clone Repository and Initialize Git Source: https://github.com/get-convex/v1/blob/main/README.md This snippet outlines the initial steps for manually setting up the project, including cloning the repository using `bunx degit` and initializing a Git repository with an initial commit. ```bash bunx degit get-convex/v1 v1 cd v1 git init && git commit -am 'initial commit' ``` -------------------------------- ### Create a New v1 Project with Bun CLI Source: https://github.com/get-convex/v1/blob/main/README.md This command uses the Bun CLI to scaffold a new v1 project. It automates the setup process, including cloning the repository, installing dependencies, initializing the Convex backend, configuring authentication, and setting up environment variables. ```bash bun create @convex-dev/v1@latest ``` -------------------------------- ### Start the Development Server Source: https://github.com/get-convex/v1/blob/main/README.md After creating your project, navigate into its directory and use this command to start the local development server. This will launch the application, allowing you to begin development. ```bash cd your-project-name bun dev ``` -------------------------------- ### Manual Project Setup: Initialize Polar Products and Seed Database Source: https://github.com/get-convex/v1/blob/main/README.md Change directory to the backend package and execute the `convex run init` command to initialize Polar products and seed the database. ```bash cd packages/backend bunx convex run init ``` -------------------------------- ### Service Setup: Configure Cal.com Environment Variable (Optional) Source: https://github.com/get-convex/v1/blob/main/README.md Instructions for setting up the public Cal.com link as an optional environment variable in `apps/web/.env`. ```APIDOC # Your public Cal.com link, e.g., 'https://cal.com/yourusername' NEXT_PUBLIC_CAL_LINK=https://cal.com/your-username ``` -------------------------------- ### Service Setup: Configure Resend Environment Variables Source: https://github.com/get-convex/v1/blob/main/README.md Instructions for setting up Resend API key and optional sender email for authentication emails as environment variables in `packages/backend/.env`. ```APIDOC # The API key from Resend dashboard under 'API Keys'. Starts with 're_' RESEND_API_KEY=re_foobarfoobarfoobarfoobarfoobar42 # (Optional) The email address you want to use as the sender for authentication emails # Make sure it's verified in your Resend account under 'Domains' RESEND_SENDER_EMAIL_AUTH=auth@yourdomain.com ``` -------------------------------- ### Service Setup: Configure Convex Environment Variables Source: https://github.com/get-convex/v1/blob/main/README.md Instructions for setting up the Convex URL as an environment variable in `apps/web/.env` and `apps/app/.env`, obtained from the Convex dashboard. ```APIDOC # The Convex URL from the dashboard. It should look like 'https://example-123.convex.cloud' NEXT_PUBLIC_CONVEX_URL=https://foobar-42.convex.cloud ``` -------------------------------- ### Service Setup: Configure Sentry Environment Variables Source: https://github.com/get-convex/v1/blob/main/README.md Instructions for setting up Sentry DSN, auth token, organization slug, and project name as environment variables in `apps/app/.env` for error tracking. ```APIDOC # The DSN from Sentry dashboard under 'Settings' > 'Projects' > [Your Project] > 'Client Keys (DSN)' NEXT_PUBLIC_SENTRY_DSN=https://foobarfoobar42@foobar42.ingest.sentry.io/42424242 # The auth token generated in Sentry dashboard under 'Settings' > 'Auth Tokens' SENTRY_AUTH_TOKEN=foobarfoobarfoobarfoobarfoobar42 # Your Sentry organization slug, found in the URL when in your Sentry dashboard SENTRY_ORG=your-org-name # The name of your Sentry project SENTRY_PROJECT=your-project-name ``` -------------------------------- ### Service Setup: Configure OpenPanel Environment Variables Source: https://github.com/get-convex/v1/blob/main/README.md Instructions for setting up OpenPanel secret key and client ID environment variables. The secret key is for `apps/app/.env`, and the client ID is for both `apps/web/.env` and `apps/app/.env`. ```APIDOC # The secret key from OpenPanel dashboard under 'Settings' > 'Projects'. Starts with 'sec_' OPENPANEL_SECRET_KEY=sec_foobarfoobarfoobarfoobar42 # The client ID from OpenPanel dashboard under 'Settings' > 'Projects' NEXT_PUBLIC_OPENPANEL_CLIENT_ID=foo-bar-42-baz-qux-42 ``` -------------------------------- ### Production Environment Variables for Convex Vercel Deployment Source: https://github.com/get-convex/v1/blob/main/README.md This section defines essential environment variables required for deploying Convex-backed Next.js applications to production, specifically on Vercel. It details their purpose, whether they are optional or required, and example values. ```APIDOC NEXT_PUBLIC_APP_URL: Optional: for apps/web Description: The URL for your deployed app, e.g., https://your-app.vercel.app. It is used by the marketing site to link to the app. NEXT_PUBLIC_CONVEX_URL: Required: for both apps Description: The URL for your deployed Convex instance, e.g., https://your-project-name.convex.cloud. ``` -------------------------------- ### Service Setup: Configure Polar Environment Variables Source: https://github.com/get-convex/v1/blob/main/README.md Instructions for setting up Polar organization token and webhook secret as environment variables in `packages/backend/.env`. The organization token requires specific permissions, and the webhook secret is for events pointing to the Convex deployment. ```APIDOC # Generate this in Polar dashboard under 'Account' > 'Developer settings' # Required permissions: # products:read, products:write, # subscriptions:read, subscriptions:write, # customers:read, customers:write, # checkouts:read, checkouts:write, # checkout_links:read, checkout_links:write, # customer_portal:read, customer_portal:write, # customer_sessions:write POLAR_ORGANIZATION_TOKEN=polar_oat_foobarfoobarfoobarfoobarfoobar42 # Create a webhook in Polar dashboard under 'Settings' > 'Webhooks' # The webhook should point to: https://your-convex-deployment.convex.site/polar/events POLAR_WEBHOOK_SECRET=whsec_foobarfoobarfoobarfoobarfoobar42 ``` -------------------------------- ### Project Directory Structure Overview Source: https://github.com/get-convex/v1/blob/main/README.md This snippet illustrates the monorepo's directory structure, detailing the organization of applications, shared packages, and tooling configurations within the v1 project. ```text . ├── apps # App workspace │ ├── app # App - your product │ ├── web # Marketing site │ └── ... ├── packages # Shared packages between apps │ ├── analytics # OpenPanel analytics │ ├── backend # Convex (API, Auth, Database, Storage, Background Jobs, Validated Server Actions, Cache, Rate Limiting) │ ├── email # React email library │ ├── logger # Logger library │ └── ui # Shared UI components (Shadcn) ├── tooling # are the shared configuration that are used by the apps and packages │ └── typescript # Shared TypeScript configuration ├── .cursorrules # Cursor rules specific to this project ├── biome.json # Biome configuration ├── turbo.json # Turbo configuration ├── LICENSE └── README.md ``` -------------------------------- ### Configure Google OAuth 2.0 Environment Variables Source: https://github.com/get-convex/v1/blob/main/README.md This snippet demonstrates how to add Google OAuth 2.0 client ID and secret to the backend environment variables (`.env`) for enabling Google authentication in your application. These credentials are obtained from your Google Cloud Console. ```Shell AUTH_GOOGLE_ID=424242424242-foobarfoobarfoobarfoobar42.apps.googleusercontent.com AUTH_GOOGLE_SECRET=GOCSPX-foobarfoobarfoobarfoobar42 ``` -------------------------------- ### Configure Loops Integration Environment Variable Source: https://github.com/get-convex/v1/blob/main/README.md This snippet shows how to add the Loops form ID to the backend environment variables (`.env`) for integrating Loops.so with your application. The `LOOPS_FORM_ID` is found in the Loops dashboard. ```Shell LOOPS_FORM_ID=foobarfoobar42 ``` -------------------------------- ### Define a Convex Query Function in TypeScript Source: https://github.com/get-convex/v1/blob/main/packages/backend/convex/README.md This snippet defines a Convex query function named `myQueryFunction` that takes a number and a string as arguments. It demonstrates how to read data from the database using `ctx.db.query` and return documents. Arguments passed from the client are accessible via the `args` object. ```ts import { query } from "./_generated/server"; import { v } from "convex/values"; export const myQueryFunction = query({ // Validators for arguments. args: { first: v.number(), second: v.string() }, // Function implementation. handler: async (ctx, args) => { // Read the database as many times as you need here. // See https://docs.convex.dev/database/reading-data. const documents = await ctx.db.query("tablename").collect(); // Arguments passed from the client are properties of the args object. console.log(args.first, args.second); // Write arbitrary JavaScript here: filter, aggregate, build derived data, // remove non-public properties, or create new objects. return documents; } }); ``` -------------------------------- ### Define a Convex Mutation Function in TypeScript Source: https://github.com/get-convex/v1/blob/main/packages/backend/convex/README.md This snippet defines a Convex mutation function named `myMutationFunction` that takes two strings as arguments. It demonstrates how to insert new documents into the database using `ctx.db.insert` and optionally return a value after the mutation completes. Mutations can also read from the database. ```ts import { mutation } from "./_generated/server"; import { v } from "convex/values"; export const myMutationFunction = mutation({ // Validators for arguments. args: { first: v.string(), second: v.string() }, // Function implementation. handler: async (ctx, args) => { // Insert or modify documents in the database here. // Mutations can also read from the database like queries. // See https://docs.convex.dev/database/writing-data. const message = { body: args.first, author: args.second }; const id = await ctx.db.insert("messages", message); // Optionally, return a value from your mutation. return await ctx.db.get(id); } }); ``` -------------------------------- ### Use a Convex Query Function in a React Component Source: https://github.com/get-convex/v1/blob/main/packages/backend/convex/README.md This snippet shows how to use the `useQuery` hook from Convex to call a defined query function (`api.functions.myQueryFunction`) within a React component, passing the required arguments. ```ts const data = useQuery(api.functions.myQueryFunction, { first: 10, second: "hello" }); ``` -------------------------------- ### Use a Convex Mutation Function in a React Component Source: https://github.com/get-convex/v1/blob/main/packages/backend/convex/README.md This snippet illustrates how to use the `useMutation` hook from Convex to call a defined mutation function (`api.functions.myMutationFunction`) within a React component. It shows both fire-and-forget usage and handling the result of the mutation with a promise. ```ts const mutation = useMutation(api.functions.myMutationFunction); function handleButtonPress() { // fire and forget, the most common way to use mutations mutation({ first: "Hello!", second: "me" }); // OR // use the result once the mutation has completed mutation({ first: "Hello!", second: "me" }).then((result) => console.log(result) ); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.