Better Auth for Go
Email & password, sessions, social OAuth, plugins, and a CLI โ mount it on any Go server and point your Better Auth client at it.
go get github.com/patrickkabwe/betterauth-go
Setup in seconds
Create an instance, mount the handler. That's the whole server.
package main
import (
"log"
"net/http"
"github.com/patrickkabwe/betterauth-go/auth"
"github.com/patrickkabwe/betterauth-go/store/memory"
)
func main() {
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(), // or store/sql for Postgres/SQLite/MySQL
})
if err != nil {
log.Fatal(err)
}
mux := http.NewServeMux()
// Mount every Better Auth endpoint under /api/auth
mux.Handle("/api/auth/", http.StripPrefix("/api/auth", a.Handler()))
log.Fatal(http.ListenAndServe(":8080", mux))
}
Works with net/http, chi, Gin, Echo, Fiber
โ anything that speaks http.Handler.
Connect any Better Auth client
The wire format matches the official server, so existing clients just work.
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient({
baseURL: "http://localhost:8080", // your Go server
});
await authClient.signUp.email({ name: "Jane", email: "jane@example.com", password: "securepass" });
const { data: session } = await authClient.getSession();
Everything you need to ship auth
Feature parity with the TypeScript server, idiomatic Go.
Email & password
Sign-up/in/out, verification, password reset, scrypt hashing, enumeration protection.
Sessions
Signed cookies, cookie cache, refresh, fresh-session checks, bearer tokens, multi-session.
Social OAuth
Google & GitHub built in, generic OAuth plugin, account linking, token refresh.
24 plugins
Organization, admin, 2FA, magic link, email OTP, passkey-adjacent, OIDC provider & more.
SQL adapters
Driver-agnostic Postgres / SQLite / MySQL, or
bring any ORM via the
Store interface.
Production middleware
CORS with wildcards, origin CSRF, per-path rate limiting, secret rotation, DB hooks.
A CLI that matches @better-auth/cli
Generate a feature-scoped schema, migrate, scaffold, and more.
# install the CLI
go install github.com/patrickkabwe/betterauth-go@latest
betterauth-go secret # generate BETTER_AUTH_SECRET
betterauth-go generate --plugins organization # schema for enabled features only
betterauth-go migrate --database "file:auth.db" # apply it
betterauth-go init --name "My App" # scaffold a project
Schema is feature-scoped: only the tables your enabled plugins need are generated.