---
title: "Handling Auth in a Staging Environment"
description: "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."
url: "https://swe.quest/articles/handling-auth-in-a-staging-environment-18efe1e68fa29994"
canonical: "https://neon.com/blog/handling-auth-in-a-staging-environment"
source: "Neon"
published: "2026-01-10"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 7
tags: ["identity-auth","postgres","ci-cd","testing"]
---

# Handling Auth in a Staging Environment

A post on [Neon](https://swe.quest/sources/neon.md), published 2026-01-10, 7 min read, Announcement. Original: [https://neon.com/blog/handling-auth-in-a-staging-environment](https://neon.com/blog/handling-auth-in-a-staging-environment)

## Summary

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.

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)
- [CI/CD](https://swe.quest/tags/ci-cd.md) (Reliability & operations)
- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)

## Prerequisites

- Postgres schemas ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- preview environments in CI/CD ([easy posts on CI/CD](https://swe.quest/tags/ci-cd.md?difficulty=easy))
- authentication providers ([easy posts on Identity & auth](https://swe.quest/tags/identity-auth.md?difficulty=easy))

## Keywords

Neon Auth, Neon, Better Auth, neon-js, GitHub Actions, copy-on-write branching

## Related posts

- [Stop Mocking Auth (It’s Breaking Your Tests)](https://swe.quest/articles/stop-mocking-auth-it-s-breaking-your-tests-f37ca9cbb9aaf394.md): Neon · 2025-12-29 · Medium · 8 min read · Testing, Identity & auth, PostgreSQL, CI/CD
  Mocking authentication in tests hides real failures: password hashing and verification, UNIQUE-constraint enforcement under concurrent signups, session handling, and SQL joins between auth and application data.
- [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.
- [Branching Postgres databases with the Neon API](https://swe.quest/articles/branching-postgres-databases-with-the-neon-api-3faf0de941bc811a.md): Neon · 2022-12-07 · Medium · 3 min read · PostgreSQL, CI/CD, Testing
  Neon branches are copy-on-write clones of a Postgres database that can be created and deleted through the Neon API, giving CI pipelines an isolated copy of production data for end-to-end tests.
- [Adopting Neon branching in CI/CD pipelines: a practical story by Shepherd](https://swe.quest/articles/adopting-neon-branching-in-ci-cd-pipelines-a-practical-story-by-shepherd-7c4ee09d2fb5431a.md): Neon · 2024-07-11 · Medium · 5 min read · CI/CD, PostgreSQL, Schema migrations, Testing, Serverless
  Shepherd, an insurtech startup that moved its Alchemist pricing engine from SQLite to Postgres, uses Neon's copy-on-write database branches to give every pull request an ephemeral test database.
- [Behind Modem.dev’s Product Velocity](https://swe.quest/articles/behind-modem-dev-s-product-velocity-485adbdf853a0161.md): Neon · 2026-01-29 · Medium · 4 min read · PostgreSQL, Schema migrations, CI/CD, Developer productivity
  Modem, a startup building an AI agent that centralizes user feedback from Slack, Discord and GitHub, uses Neon Postgres branching as its development workflow.

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)
