Skip to Content
Authentication

Authentication

MeetAI uses Better Auth — a framework-agnostic authentication library with first-class Drizzle ORM integration, OAuth providers, and plugin support for payments.

Auth Architecture

Providers

ProviderTypeFlow
GitHubOAuth 2.0GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET
GoogleOAuth 2.0GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET
EmailCredentialemailAndPassword: { enabled: true }

Middleware Protection

The Next.js middleware (src/middleware.ts) implements cookie-based session checking:

// Check for session token across cookie name variants const hasToken = request.cookies.has("session_token") || request.cookies.has("__Secure-session_token") || request.cookies.has("better-auth.session_token") || request.cookies.has("__Secure-better-auth.session_token");

Route Protection Rules

Route PatternAccessReasoning
/PublicLanding page
/_next/*, /api/*, static filesPublicFramework assets
/sign-in, /sign-upPublic (redirects if authed)Auth pages
/agents/*, /meetings/*, /upgradeProtectedDashboard routes
/call/*ProtectedMeeting rooms

Polar.sh Integration

Better Auth’s Polar plugin enables subscription gating:

plugins: [ polar({ client: polarClient, createCustomerOnSignUp: true, // Auto-create Polar customer use: [ checkout({ authenticatedUsersOnly: true, successUrl: "/upgrade" }), portal(), // Customer self-service portal ], }), ],

How it works: When a user signs up, Polar automatically creates a customer record. The checkout sub-plugin restricts purchase flows to authenticated users. The portal sub-plugin gives users access to manage their subscription.

Database Tables

Better Auth manages four tables through the Drizzle adapter:

  • user — Core identity (id, name, email, image)
  • session — Active sessions with token, expiry, IP, user-agent
  • account — Linked OAuth providers (GitHub, Google) per user
  • verification — Email verification tokens

All foreign keys cascade on delete — removing a user automatically cleans up sessions, accounts, and all related meeting data.

Last updated on