Skip to main content

Authentication

OpenFinance uses BetterAuth for authentication. It supports email/password sign-up and optional Google OAuth.

Auth Endpoints

BetterAuth exposes its endpoints under /api/auth/. The main endpoints are:

Session Management

When a user signs in, BetterAuth creates a session stored in the database and sets a session cookie in the browser. Session configuration: The session token is stored in the better-auth.session_token cookie. All authenticated API requests must include this cookie.

Sign Up

Create a new account by sending a POST request:
Password requirements:
  • Minimum 8 characters
  • Maximum 128 characters

Sign In

Authenticate with email and password:
The response sets a session cookie that is used for subsequent authenticated requests.

Google OAuth (Optional)

To enable “Sign in with Google”, set the following environment variables:
When configured, a Google sign-in button appears on the login page. Users can then sign in with their Google account.

Client-Side Usage

The app uses the BetterAuth client SDK for authentication in React components:

Server-Side Usage

In server components and API routes, use the auth object to check the session: