Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 16 min read How-to mediumAdept

Authenticating users in Astro using Neon Postgres and Lucia Auth

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.

Assumes: TypeScript basicsNode.js and npmSQL table basicsHTTP cookies and sessions

Related posts

  • Handling Auth in a Staging Environment

    Neon mediumAdept

    Neon Auth stores users, sessions and OAuth data in a neon_auth schema inside the Postgres database, so branching the database also branches auth state via copy-on-write. Each branch gets its own auth endpoint, which lets preview and staging environments test role, permission and OAuth changes against a copy of production users without touching production or creating test accounts by hand. Deleting the branch removes all copied users. It is built on Better Auth, used through the @neondatabase/neon-js SDK, and can be provisioned per PR with a GitHub Action that outputs the branch's auth URL.

  • Next.js authentication using Clerk, Drizzle ORM, and Neon

    Neon mediumAdept

    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.

  • 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.

  • Meet the New Neon Auth: Branchable Identity in Your Database

    Neon easyNovice

    Neon Auth has been rebuilt on Better Auth and now stores users, sessions, organizations and auth configuration in a neon_auth schema inside the Neon Postgres database. This replaces the earlier external-provider setup that relied on webhook sync. Because identity lives in the database, auth state clones with every branch, and each branch gets its own isolated auth endpoint co-located with compute. RLS policies can reference the JWT user, and user creation plus role assignment can happen in one transaction. A unified neon-js SDK ties together Auth, the Data API and the database, though Neon Auth does not yet support custom Better Auth plugins or server-side handlers.

  • Build a Dynamic E-Commerce Store UI with Astro, Neon Postgres, and AWS Amplify

    Neon mediumAdept

    An e-commerce storefront built with Astro in server-rendered mode, reading products from Neon serverless Postgres over HTTP through the @neondatabase/serverless driver and deployed to AWS Amplify on every Git commit. The walkthrough covers provisioning a pooled Neon connection string, adding Tailwind, configuring the astro-aws-amplify adapter and an amplify.yml that copies node_modules and .env into the compute bundle, and seeding a products table with a tsx script. It then builds a shared layout, a product listing page, and a dynamic /p/[slug] product page.

The quest for software engineering knowledge.

Look:
Layout: