This template provides a minimal setup to get Convex working with Next.js. It uses Auth.js for user authentication.
Clone the template and install dependencies:
npm create convex@latest -- -t get-convex/convex-nextauth-template
Then:
- Run
npx convex dev --once
, and follow the steps to provision a Convex backend - Generate private and public key by running
node generateKeys.mjs
- Paste the private key to the
.env.local
file - Paste the public key to your Convex dashboard, which you can open by
running
npx convex dashboard
- Paste the private key to the
- Generate a random secret (via
openssl rand -base64 33
ornpx auth secret
) and save it asAUTH_SECRET
to the.env.local
file - Generate another random secret and save it as
CONVEX_AUTH_ADAPTER_SECRET
to- the
.env.local
file - to your Convex dashboard
- the
- Follow
this guide
to create a GitHub OAuth app and then add
AUTH_GITHUB_ID
andAUTH_GITHUB_SECRET
to.env.local
- Follow
this guide
to sign up for Resend and then add
AUTH_RESEND_KEY
to.env.local
Now your .env.local
should match .env.example
and there should be JWKS
and
CONVEX_AUTH_ADAPTER_SECRET
variables on your Convex dashboard.
You can now run:
npm run dev
and open your app at http://localhost:3000
See Convex docs at https://docs.convex.dev/home