← Back to archive

Repo of the Day

patrickkabwe/betterauth-go

Published: Nov 22, 2026

Open repository ↗

A Go server implementation compatible with Better Auth clients - React, Vue, Svelte, Solid, and the framework-agnostic client

Summary

betterauth-go is a Go implementation of the server-side authentication API expected by Better Auth clients for React, Vue, Svelte, Solid, and framework-agnostic applications. It provides email/password authentication, session management, pluggable persistence, middleware, database hooks, and 24 core plugins while aiming for compatibility with the TypeScript Better Auth server.

What it is useful for

This repository is useful when a frontend already uses better-auth but the backend needs to run in Go. For example, a React application can call signUp.email, getSession, and useSession without replacing its client-side auth layer.

The server supports signed session cookies using HMAC-SHA256 and scrypt password hashes in a format compatible with the TypeScript implementation. Persistence can use the included in-memory store, SQL adapters for PostgreSQL, SQLite, or MySQL, or a custom implementation of the store.Store interface.

It also provides practical production controls: credentials-aware CORS, origin-based CSRF protection, per-path rate limiting, secret rotation, proxy-aware IP headers, and cross-subdomain cookie settings. Plugins cover bearer tokens, JWT, organizations, administration, two-factor authentication, magic links, email OTPs, and OIDC.

How engineers can use it

Create an auth.Auth instance with a secret, base URL, trusted frontend origins, and a store, then mount its handler at the default /api/auth path:

a, err := auth.New(auth.Config{
    Secret:         "your-secret-at-least-32-chars-long",
    BaseURL:        "http://localhost:8080",
    TrustedOrigins: []string{"http://localhost:3000"},
    Store:          memory.New(),
})
if err != nil {
    log.Fatal(err)
}

mux := http.NewServeMux()
mux.Handle("/api/auth/", http.StripPrefix("/api/auth", a.Handler()))
log.Fatal(http.ListenAndServe(":8080", mux))

From a repository checkout, the documented basic server can be started with:

go run ./examples/basic

The bundled React example uses the standard Better Auth client:

import { createAuthClient } from "better-auth/react";

export const authClient = createAuthClient({
  baseURL: "http://localhost:8080",
});

To run that example, use cd examples/client, then npm install and npm run dev.

For persistent storage, the README shows opening a *sql.DB, selecting sqlstore.Postgres, sqlstore.SQLite, or sqlstore.MySQL, and calling Migrate(context.Background()). A CLI is also available through go install github.com/patrickkabwe/betterauth-go@latest; documented commands include secret, generate, migrate, init, and info.

Compatibility is broad but not presented as complete: the README points to the repository’s ROADMAP for the full feature-parity tracker, so engineers should verify required endpoints and plugin behavior before production adoption.