Documentation Index
Fetch the complete documentation index at: https://mintlify.com/get-convex/better-auth/llms.txt
Use this file to discover all available pages before exploring further.
Better Auth guide
Better Auth’s basic usage guide applies to Convex as well. It covers signing in and out, social providers, plugins, and more. You will be using Better Auth directly in your project, so their guides are a primary reference.Exceptions
There are a few areas in the Better Auth basic usage guide that work differently in Convex.Server side authentication
Server side authentication
Better Auth supports signing users in and out through server side functions.
Because Convex functions run over websockets and don’t return HTTP responses
or set cookies, signing up/in/out must be done from the client via
authClient.signIn.* methods.Schemas and migrations
Schemas and migrations
The basic usage guide includes information on database schema generation and
migrations via the Better Auth CLI. This only applies for
Local Install, which supports generating schemas. For
projects not using local install, the default schema provided with the Better
Auth component (preconfigured with the
supported plugins) is used, and cannot be altered.
Using server methods with auth.api
Better Auth’s server side auth.api methods can be used with your createAuth function and the component headers method. The authComponent.getAuth(createAuth, ctx) call returns both an auth object and headers constructed from the current session token.
Here’s an example implementing the changePassword server method:
convex/users.ts
Using Convex ctx in Better Auth config
Thectx param passed in to the createAuth function is the Convex context object. This can be used to access the Convex database or Convex functions in your Better Auth config. It can be a query, mutation, or action context.
Type guard utilities
Becausectx can be any of the three context types, the library exports type guards to narrow it when a specific context type is required.
| Utility | Import | Description |
|---|---|---|
requireActionCtx(ctx) | @convex-dev/better-auth/utils | Narrows to GenericActionCtx. Throws if ctx is not an action context. |
requireRunMutationCtx(ctx) | @convex-dev/better-auth/utils | Narrows to a ctx with runMutation. Throws if neither mutation nor action. |
requireMutationCtx(ctx) | @convex-dev/better-auth/utils | Narrows to GenericMutationCtx. Throws if not a mutation context. |
requireQueryCtx(ctx) | @convex-dev/better-auth/utils | Narrows to GenericQueryCtx. Throws if not a query context. |
Example: sending emails with Resend
A common use case is sending emails for verification or password resets with the Resend component. Callingresend.sendEmail directly would produce a type error because the ctx object could be a query ctx — network requests require an action ctx. Use requireActionCtx to narrow the type:
convex/auth.ts