Skip to content

Sign-in and teams

Better-auth with accounts, or with organizations, roles and invitations.

Requires:DatabaseEmails

Structure

Pick one to update the preview and files

List prices at the time of writing. Verify before you rely on them.

Preview

What it adds

9 things, working end to end
  • Email and password sign-up and login, with email verification required
  • Forgot-password and reset-password pages
  • Google sign-in, switched on by two environment variables
  • Protected route groups with a session guard
  • Account settings: details, language and delete account
  • Organization-based: create and select organizations, a members table, an organization switcher and delete organization
  • Organization-based: invite members by email with the roles member, admin or owner, and an accept-invitation page
  • Verification, reset and invitation emails sent through your email provider
  • Prisma models in prisma/schema/auth.prisma (User, Session, Account, Verification, plus Organization, Member, Invitation)

Set up User-based

Accounts and keys, in this order
  1. 1
    Generate a secretBetter Auth signs sessions with a random secret.
    openssl rand -base64 32
  2. 2
    Set the secret and URLsUse your real domain in production.
    .env
    BETTER_AUTH_SECRET="paste-the-output-here"
    BETTER_AUTH_URL="http://localhost:3000"
    NEXT_PUBLIC_APP_URL="http://localhost:3000"
  3. 3
    Optional: Google sign-inCreate an OAuth client and add the redirect URI. Email sign-in works without it.console.cloud.google.comAPIs & ServicesCredentialsCreate OAuth client ID
    .env
    Redirect URI: http://localhost:3000/api/auth/callback/google
    GOOGLE_CLIENT_ID="...apps.googleusercontent.com"
    GOOGLE_CLIENT_SECRET="..."
  4. 4
    Check it worksOpen /signup and create an account. Sign-in requires a verified email, so set up Email first; then sign in at /login.

Environment variables

For the selected provider
.env
# Base URL of the app
BETTER_AUTH_URL=
# Random secret that signs sessions: openssl rand -base64 32
BETTER_AUTH_SECRET=
# Public URL of the app
NEXT_PUBLIC_APP_URL=
# Google OAuth client id, to enable Google sign-in (optional)
GOOGLE_CLIENT_ID=
# Google OAuth client secret (optional)
GOOGLE_CLIENT_SECRET=

Works with

Other modules this one connects to

Add it to your repo

Pick the preset in the builder, check the providers, and download a repo that already has this module wired in.

Build your repo