Zum Hauptinhalt springen

Next.js Authentication with Better Auth and PostgreSQL

Registrierung, Anmeldung und Abmeldung per E-Mail und Passwort für Next.js 16 mit Better Auth, PostgreSQL in Docker, einer Prüfung der Einstellungen beim Start und Tests.

  • Next.js
  • React
  • Better Auth
  • PostgreSQL
  • pg (node-postgres)

Bildschirmfotos

Bildschirmfoto 1 von 10: Titelkarte: Next.js Authentication with Better Auth and PostgreSQL mit Versprechen, Technologien, echtem Log von npm run dev samt erfolgreicher Registrierung und angemeldeter Startseite am Smartphone.

Titelkarte: Next.js Authentication with Better Auth and PostgreSQL mit Versprechen, Technologien, echtem Log von npm run dev samt erfolgreicher Registrierung und angemeldeter Startseite am Smartphone.

Einmaliger Preis

  • 199 ₹zzgl. GST, insgesamt 234,82 ₹
  • 3 $
  • Laden Sie es aus Ihrer Bibliothek herunter, sobald Ihre Zahlung bestätigt ist.
  • Alle künftigen Releases dieses Projekts sind ohne Aufpreis enthalten.
Neuestes Release
1.0.0 · 19.11.2026

Überblick

Der vollständige Quellcode einer App mit Next.js 16 und Konten mit E-Mail und Passwort über Better Auth 1.7: Registrierungs- und Anmeldeseiten mit klaren Fehlermeldungen, Abmeldung und eine Kopfzeile, die zeigt, wer angemeldet ist. Die Konten liegen in PostgreSQL 18 in Docker. Die App prüft beim Start ihre Einstellungen; fünf Tests decken das ab. Getestet auf macOS mit Docker Desktop.

Eine Anmeldung sieht nach zwei kleinen Formularen aus, bedeutet aber auch gehashte Passwörter, ein sicheres Sitzungscookie, klare Fehlermeldungen und Einstellungen, die geprüft werden, bevor etwas kaputtgeht. Next.js Authentication with Better Auth and PostgreSQL erledigt all das mit Better Auth, der Open-Source-Bibliothek für Authentifizierung mit TypeScript, in einer kleinen App, die Sie auf Ihrem Computer ausführen und weiterentwickeln können. Die App wurde in echten Läufen auf macOS mit Docker Desktop getestet.

Was sie macht

  • Registrierung mit E-Mail-Adresse und Passwort. Die Registrierungsseite legt das Konto an und meldet die Person sofort an.
  • Anmelden und abmelden. Die Anmeldeseite meldet eine Person wieder an, und die Schaltfläche Sign out beendet die Sitzung in diesem Browser.
  • Zeigt, wer angemeldet ist. Die Kopfzeile jeder Seite zeigt den Namen der angemeldeten Person mit einer Schaltfläche Sign out oder die Links Sign in und Sign up und wechselt ohne Neuladen der Seite.
  • Klare Meldungen in den Formularen. User already exists. Use another email. und Invalid email or password erscheinen direkt im Formular.

Sichere Standardeinstellungen von Better Auth

  • Keine Passwörter im Klartext. Better Auth speichert in PostgreSQL nur einen scrypt-Hash jedes Passworts.
  • Sitzungen in einem HttpOnly-Cookie. Skripte auf der Seite können es nicht lesen, und eine Sitzung ist standardmäßig 7 Tage gültig.
  • Passwortlänge auf dem Server geprüft. 8 bis 128 Zeichen, mit demselben Minimum im Formular.

So gebaut, dass Fehler früh auffallen

  • Eine Prüfung der Einstellungen beim Start. Fehlt BETTER_AUTH_SECRET, BETTER_AUTH_URL oder DATABASE_URL oder ist ein Wert ungültig, stoppt die App mit einer klaren Liste dessen, was zu beheben ist.
  • Fünf Tests für diese Prüfung, ausgeführt mit dem in Node.js eingebauten Test-Runner, also ohne Test-Framework, das Sie installieren müssten.
  • Saubere Prüfungen. Die TypeScript-Typprüfung und der Linter Biome laufen fehlerfrei durch, und npm run build ist erfolgreich.

Code, auf dem Sie aufbauen können

  • Next.js 16 mit dem App Router, TypeScript 7, Tailwind CSS 4 und Biome.
  • Better Auth 1.7 mit PostgreSQL über einen pg-Verbindungspool: eine kurze lib/auth.ts, der Route Handler und der React-Client.
  • PostgreSQL 18 in Docker Compose, nur von Ihrem eigenen Computer aus erreichbar, auf Port 5435.
  • Alle Einstellungen in einer Datei. Kopieren Sie .env.example nach .env; die README erklärt jeden Wert.
  • Reproduzierbare Installationen. Eine package-lock.json mit den exakten Paketversionen und eine .nvmrc für Node.js 26.

Was nicht enthalten ist

  • Keine E-Mails. Es gibt keine E-Mail-Bestätigung und kein Zurücksetzen des Passworts.
  • Keine Anmeldung über soziale Netzwerke, keine Zwei-Faktor-Authentifizierung und keine Passkeys.
  • Keine geschützten Seiten. Jede Seite ist öffentlich; die Kopfzeile zeigt die Sitzung.
  • Kein Hosting. Die App läuft auf Ihrem Computer. Das Deployment liegt bei Ihnen.

In sechs Schritten zum Laufen bringen

  1. Installieren Sie Node.js 26 LTS und starten Sie Docker Desktop.
  2. Entpacken Sie den Download und öffnen Sie ein Terminal in seinem Ordner.
  3. Führen Sie npm install aus.
  4. Kopieren Sie .env.example nach .env. Führen Sie npx auth@latest secret aus und fügen Sie die ausgegebene Zeile in .env ein.
  5. Führen Sie docker compose up -d und dann npx auth@latest migrate aus, und antworten Sie mit y.
  6. Führen Sie npm run dev aus, öffnen Sie http://localhost:3000 und klicken Sie auf Sign up.

Jeder Schritt mit Screenshots: How to Set Up and Run Next.js Authentication with Better Auth and PostgreSQL (öffnet in einem neuen Tab) (auf Englisch).

Die Ideen hinter dem Code lernen Sie im kostenlosen Better Auth Tutorial for Beginners (öffnet in einem neuen Tab) (auf Englisch).

Better Auth, Next.js, PostgreSQL, Docker und andere genannte Namen sind Marken ihrer jeweiligen Inhaber. Dieses Projekt steht in keiner Verbindung zu Better Auth, Inc. oder Vercel und wird von diesen nicht befürwortet.

Kostenlose Tutorial-Reihe

Better Auth Tutorial for Beginners

Sie lernen lieber beim Nachbauen? Diese kostenlose Schritt-für-Schritt-Anleitung in unserem Blog zeigt, wie das Projekt entsteht.

Reihe lesen (öffnet in einem neuen Tab)

Das bekommen Sie

Alles im Archiv, auf einen Blick.

  • Version 1.0.0 des vollständigen Quellcodes der Next.js-App
  • Registrierungs- und Anmeldeseiten mit klaren Fehlermeldungen
  • Eine Kopfzeile, die zeigt, wer angemeldet ist, mit einer Schaltfläche Sign out
  • Better Auth 1.7, eingerichtet mit PostgreSQL, samt Route Handler und React-Client
  • Eine Datei für Docker Compose, die PostgreSQL 18 auf Ihrem Computer ausführt
  • Eine Prüfung der Einstellungen, die die App mit einer klaren Meldung stoppt, wenn eine Einstellung fehlt oder ungültig ist
  • Fünf Tests für die Prüfung der Einstellungen
  • Eine Beispieldatei für die Einstellungen, eine Lock-Datei für die Pakete und eine .nvmrc-Datei
  • Eine README mit Voraussetzungen, Einrichtung, allen Einstellungen, den Skripten und Fehlerbehebung

Gebaut mit

Die genauen Laufzeitumgebungen und Versionen, mit denen gebaut und getestet wurde.

  • Next.js16.4.6
  • React19.3.1
  • Better Auth1.7.26
  • PostgreSQL18.7
  • pg (node-postgres)8.23.1
  • TypeScript7.0.2
  • Tailwind CSS4.3.5
  • Biome2.6.8
  • Node.js26.13.1
  • Docker Desktop4.99.0

Was im Archiv liegt

Der Dateibaum, den Sie nach dem Entpacken vor sich haben.

nextjs-authentication-better-auth-postgresql/

  • .env.example
  • .gitattributes
  • .gitignore
  • .nvmrc
  • AGENTS.md
  • README.md
  • app/
    • api/
      • auth/
        • [...all]/
          • route.ts
    • favicon.ico
    • globals.css
    • layout.tsx
    • page.tsx
    • sign-in/
      • page.tsx
    • sign-up/
      • page.tsx
  • biome.json
  • components/
    • user-menu.tsx
  • compose.yaml
  • instrumentation.ts
  • lib/
    • auth-client.ts
    • auth.ts
    • env.ts
  • next.config.ts
  • package-lock.json
  • package.json
  • tests/
    • env.test.ts
  • tsconfig.json

Was es von Ihnen braucht

Die Konten und Dienste, die es voraussetzt, damit Sie später nichts überrascht.

  • Node.js 26 LTS und npm
  • Docker mit Docker Compose: Docker Desktop unter macOS oder Windows oder Docker Engine unter Linux. Docker Desktop ist privat und für kleine Unternehmen kostenlos; größere Organisationen brauchen ein kostenpflichtiges Abonnement
  • Freie Ports 3000 (die App) und 5435 (die Datenbank) auf Ihrem Computer
  • Keine weiteren Konten, API-Schlüssel oder kostenpflichtigen Dienste: Alles läuft auf Ihrem Computer

Versionen

Alle bisherigen Versionen, die neueste zuerst.

  1. 1.0.0Neueste

    Erstes Release des vollständigen Quellcodes.

    • Registrierung, Anmeldung und Abmeldung per E-Mail und Passwort mit Better Auth 1.7.26 in Next.js 16.4.6.
    • PostgreSQL 18 in Docker Compose; ein einziger Befehl legt die Tabellen von Better Auth an.
    • Eine Prüfung der Einstellungen beim Start, mit fünf Tests.

Source Code Licence

Was Sie damit tun dürfen

What you may and may not do with the source code you buy.

Vollständige Lizenz lesen
  1. What this licence covers

This licence governs every file included in a product you buy from Dewiride Store: source code, configuration, database scripts, sample data, documentation and any other file in the download. It takes effect when your payment is confirmed and applies to every release of that product that reaches your library. Files that reach your library through an annual updates membership are governed in exactly the same way.

It forms part of the Terms of Sale and Use. Where a product page states different or additional licence terms for that product, those terms prevail for that product. The membership page may likewise state different or additional licence terms for the files a membership carries, and those terms then prevail for those files.

  1. The licence we grant you

We grant you a perpetual, worldwide, non-exclusive, non-transferable licence to use, reproduce, adapt, translate and modify the files, and to include the result in your own work, on the conditions set out below.

Perpetual means it does not expire. Worldwide means it is not limited to any country. Non-exclusive means we license the same product to other customers. Non-transferable means you cannot pass it on to someone else.

The licence is granted to you — either you personally, or the organisation you identified when buying. Everyone working within that organisation may use the files for that organisation’s projects. Nobody outside it may.

  1. What you may do
  • Use and change the files in your own projects, commercial or otherwise, with no limit on the number of projects.
  • Build a product or a service on them and charge your own customers for it.
  • Deploy the result for a client, as part of work you are doing for that client.
  • Distribute the result in compiled, deployed or otherwise non-source form.
  • Keep as many back-up copies as you reasonably need.
  • Study, observe and test how the code works, and obtain the information you need to make it work with your own software.

The last two are yours by law under sections 52(1)(aa) to (ac) of the Indian Copyright Act, 1957, and nothing in this licence is intended to take them away.

  1. What you may not do
  • Resell, sublicense, redistribute or publish the files themselves, in whole or in substantial part, in source form.
  • Include them in a template, starter kit, course, tutorial repository or component library that you sell or give away, where the code is the thing being supplied.
  • Share your account, your download links or your invoices with anyone outside your organisation.
  • Publish the files in a public repository, or in any other place where they can be obtained without buying them.
  • Remove or obscure the copyright and attribution notices in the source files.
  • Use the files to build something whose main purpose is to compete with Dewiride Store as a supplier of the same code.

The distinction that matters is simple: you may sell what you build with the code; you may not sell the code.

  1. Third-party components

Our products depend on open-source libraries, frameworks and services that we did not write. Those remain under their own licences, which we do not and cannot change. Where a product includes or requires such a component, its licence is named in the product’s documentation, and complying with it is your responsibility.

  1. Releases

Every release of a product you own is covered by this same licence and appears in your library at no extra cost. A release you have already downloaded remains licensed to you even if we later stop publishing the product. A release that reached your library through an annual updates membership is licensed to you on these same terms, and stays licensed after the period that carried it has ended.

  1. Ownership

We keep ownership of the files and of the copyright in them. You own whatever you create with them: your changes, your additions and the product you build are yours.

  1. If this licence ends

This licence ends if you materially breach it and do not put the breach right within thirty days of us asking you to in writing. It also ends if your payment is reversed or refunded, because the purchase it depends on no longer stands. Where a membership period is refunded or reversed, the licence ends for the releases that period carried and for nothing else: anything you bought separately, or that another period carried, is unaffected.

If it ends, you must stop using the files and delete the copies you hold. Work you had already delivered to a client before that point may continue in use, so that ending this licence never breaks something your own customer relies on.

  1. No warranty beyond the description

The warranties and limits in section 19 and section 20 of the Terms of Sale and Use apply to this licence as well.

  1. Governing law

This licence is governed by the law of India, and section 24 of the Terms of Sale and Use applies to any dispute about it. If a translation and the English version differ in meaning, the English version governs.