A quick start Next.js template demonstrating secure user authentication and authorization using Neon Authorize with Clerk integration. This guide primarily uses SQL from the frontend to enforce row-level security policies.
- Next.js application with TypeScript
- User authentication powered by Clerk
- Row-level security using Neon Authorize
- Database migrations with Drizzle ORM
- Ready-to-deploy configuration for Vercel, Netlify, and Render
- Create a Neon project ( pg.new )
- Create a Clerk Application ( https://go.clerk.com/cHq4Ut6 )
- Node.js 18+ installed locally
Deploy directly to your preferred hosting platform:
- Navigate to your Clerk dashboard and create a new application.
- Obtain your Publishable key and Secret key from the Clerk dashboard.
- In your Clerk dashboard, go to JWT Templates.
- Create a new JWT Template (select "Blank" as the template type).
- Name your template (e.g.,
neon_authorize
). - Copy the JWKS Endpoint URL. You'll need this for Neon Authorize.
-
Open your Neon Console and click on Authorize.
-
Click Add Authentication Provider.
-
Paste the JWKS Endpoint URL you copied from Clerk into the JWKS URL field.
-
Follow the steps in the Neon UI to set up the
authenticated
role. You can skip the schema-related steps if you are just getting started with this example.
-
Clone the repository:
git clone https://github.com/neondatabase-labs/clerk-nextjs-frontend-neon-authorize cd clerk-nextjs-neon-authorize
-
Install dependencies:
npm install # or bun install
-
Create a
.env
file in the root of the project and fill the following environment variables:cp .env.template .env
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=YOUR_CLERK_PUBLISHABLE_KEY CLERK_SECRET_KEY=YOUR_CLERK_SECRET_KEY # For the `neondb_owner` role. DATABASE_URL="YOUR_NEON_OWNER_CONNECTION_STRING" # For the `authenticated`, passwordless role. NEXT_PUBLIC_DATABASE_AUTHENTICATED_URL="YOUR_NEON_AUTHENTICATED_CONNECTION_STRING" NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
Note: Replace the placeholder values with your actual Neon and Clerk credentials.
-
Run the database migrations:
npm run drizzle:generate # or bun run drizzle:generate npm run drizzle:migrate # or bun run drizzle:migrate
-
Start the development server:
npm run dev # or bun run dev
Before deploying to production:
- Modify your Clerk application environment to use the Production instance. Create one if you haven't already.
- Update your environment variables with the new production credentials
- Update your authentication configuration in Neon Authorize with the new JWKS URL
- Neon Authorize Tutorial
- Simplify RLS with Drizzle
- Clerk Documentation
- Postgres RLS
- Neon Authorize + Clerk Integration
Contributions are welcome! Please feel free to submit a Pull Request.