Next.js authentication using Clerk, Drizzle ORM, and Neon
Clerk can handle authentication for a Next.js 14 App Router app while Drizzle ORM and Neon's serverless HTTP driver store non-PII data keyed by the Clerk user ID. The walkthrough defines a Drizzle schema, generates and pushes migrations with Drizzle Kit, and protects routes with Clerk's authMiddleware and ClerkProvider/UserButton. It then implements Server Actions that use currentUser() to insert and delete a per-user row. PII stays in Clerk's compliant infrastructure, and only the user ID is referenced in Postgres.
Related posts
- How to Build a Secure Project Management Platform with Next.js, Clerk, and Neon
Neon mediumAdept
A security-first tutorial for building Kozi, a collaborative project management app, using Next.js, Clerk authentication and a Neon serverless Postgres database accessed through Prisma. Security rests on three layers: Clerk middleware protecting every /app route, server actions as the only path to the database so credentials never reach the client, and cross-checking the requesting user ID against record ownership on every read and write. The guide walks through the Prisma schema, the middleware configuration, sidebar and layout components, and task server actions that verify ownership before mutating data.
- Build Internal Tools Using Neon, StackAuth, and Vercel
Neon mediumAdept
An open-source Next.js template for internal tools combines Neon serverless Postgres, Stack Auth and Vercel free tiers to provide a database, API routes, authentication, role-based access control and an admin panel. Setup takes a few steps: clone the repo, fill in the env vars, push the schema with drizzle-kit, create nested admin/user roles in Neon's Auth tab, claim admin at /setup and deploy to Vercel. Access is controlled by verified-email domain whitelisting, per-email grants for contractors and explicit blocklists, all managed from /tools/admin. New tools are added under app/tools and registered in config/app.ts.
- Auth setup with Neon, Keycloak and Koyeb
Neon mediumAdept
Keycloak can use Neon serverless Postgres as its backing store, with the Keycloak server deployed as a container on Koyeb. The steps are: create a dedicated keycloak database and a scoped keycloak_admin role, then deploy Keycloak from a Koyeb template configured through KC_DB_URL, KC_DB_USERNAME, KC_DB_PASSWORD and KC_HOSTNAME. After that, import a sample realm and authenticate a Next.js app through NextAuth.js over OAuth. For production, build an optimized Keycloak image, configure connection pooling, and consider Neon branching and point-in-time restore for recovering Keycloak data.
- How to build a complete Next.js app with Vercel and CockroachDB
Cockroach Labs mediumAdeptA step-by-step build of a social events app using Next.js pages, Vercel serverless API routes, and a CockroachDB free-tier cluster accessed via the Node.js pg driver. It covers creating the cluster, the events and people tables, storing the CA certificate and connection string as Vercel environment variables, and wiring a shared pg Pool config into API routes and getServerSideProps. The React-Bootstrap pages add events, list them, collect RSVPs, and show responders per event. The example code builds SQL by string interpolation and acquires pool clients without releasing them, so real apps should use parameterized queries and release connections.
- Authenticating users in Astro using Neon Postgres and Lucia Auth
Neon mediumAdept
Lucia Auth and a Neon serverless Postgres database provide cookie-based username/password authentication in an Astro app, with Vercel as the server-side rendering target. The walkthrough provisions a pooled Neon connection, creates auth_user and user_session tables via a tsx script, and configures Lucia's NeonHTTPAdapter with secure session cookies and typed user attributes. Helper functions read and validate the auth_session cookie and check credential formats. These feed sign-in, sign-up and sign-out API routes and a protected page that blocks unauthenticated visitors.