---
title: "Authenticating users in Astro using Neon Postgres and Lucia Auth"
description: "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."
url: "https://swe.quest/articles/authenticating-users-in-astro-using-neon-postgres-and-lucia-auth-235da5a83f745233"
canonical: "https://neon.com/blog/authenticating-users-in-astro-using-neon-postgres-and-lucia-auth"
source: "Neon"
published: "2024-04-12"
difficulty: "medium"
kind: "How-to"
reading_minutes: 16
tags: ["identity-auth","postgres","typescript","frontend","serverless"]
---

# Authenticating users in Astro using Neon Postgres and Lucia Auth

A post on [Neon](https://swe.quest/sources/neon.md), published 2024-04-12, 16 min read, How-to. Original: [https://neon.com/blog/authenticating-users-in-astro-using-neon-postgres-and-lucia-auth](https://neon.com/blog/authenticating-users-in-astro-using-neon-postgres-and-lucia-auth)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Identity & auth](https://swe.quest/tags/identity-auth.md) (Security)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)

## Prerequisites

- TypeScript basics ([easy posts on TypeScript](https://swe.quest/tags/typescript.md?difficulty=easy))
- Node.js and npm ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- SQL table basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- HTTP cookies and sessions

## Keywords

Astro, Lucia Auth, Neon, Vercel, Oslo, Tailwind CSS, node-postgres

## Related posts

- [Handling Auth in a Staging Environment](https://swe.quest/articles/handling-auth-in-a-staging-environment-18efe1e68fa29994.md): Neon · 2026-01-10 · Medium · 7 min read · Identity & auth, PostgreSQL, CI/CD, Testing
  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.
- [Next.js authentication using Clerk, Drizzle ORM, and Neon](https://swe.quest/articles/next-js-authentication-using-clerk-drizzle-orm-and-neon-0a85f87be532db48.md): Neon · 2024-04-01 · Medium · 9 min read · Identity & auth, React, PostgreSQL, TypeScript, Serverless
  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.
- [Auth setup with Neon, Keycloak and Koyeb](https://swe.quest/articles/auth-setup-with-neon-keycloak-and-koyeb-120106d3cf82095b.md): Neon · 2023-12-15 · Medium · 5 min read · Identity & auth, PostgreSQL, Deployment
  Keycloak can use Neon serverless Postgres as its backing store, with the Keycloak server deployed as a container on Koyeb.
- [Meet the New Neon Auth: Branchable Identity in Your Database](https://swe.quest/articles/meet-the-new-neon-auth-branchable-identity-in-your-database-be81a13634133bac.md): Neon · 2025-12-10 · Easy · 8 min read · Identity & auth, PostgreSQL, Databases
  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.
- [Build a Dynamic E-Commerce Store UI with Astro, Neon Postgres, and AWS Amplify](https://swe.quest/articles/build-a-dynamic-e-commerce-store-ui-with-astro-neon-postgres-and-aws-amplify-5d8746c814ec14f2.md): Neon · 2024-04-09 · Medium · 12 min read · PostgreSQL, Frontend, Serverless, E-commerce, Deployment
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
