better-auth-sync is a plugin for the Better Auth system, designed to synchronize authentication data to external databases via webhooks. It offers first-class integration and helper functions specifically for Convex, enabling real-time mirroring of user and session data. The current stable version is 0.2.0, indicating it is an early-stage but actively developed package. While a specific release cadence isn't defined, its low version number suggests ongoing evolution and potential for rapid iteration. Key differentiators include its tight integration with Better Auth's plugin architecture and specialized utilities for Convex, such as schema definitions, JWT handling, and webhook verification, streamlining complex authentication setups involving external data stores.
npm install better-auth-syncVerified import paths — ran on the pinned version, not inferred.
This code snippet demonstrates how to configure Better Auth with the `better-auth-sync` plugin and `convexJwt` for JWT integration, highlighting essential environment variables for a secure setup.
Ensure `applicationID` in `convex/auth.config.ts` exactly matches the `issuer` and `audience` values provided to `convexJwt` plugin. Both typically derive from `process.env.APP_ORIGIN`.
Generate a strong, unpredictable secret using a secure random string generator. Store it in environment variables and never commit it to source control. Rotate secrets regularly.
Carefully follow the documentation for setting up the HTTP routes in `convex/http.ts`, ensuring correct paths, methods (`POST` for webhook, `GET` for JWKS), and handler functions (`verifyWebhook`, `fetchJwks`).
Pin exact versions (`~0.2.0` or `0.2.0`) rather than caret ranges (`^0.2.0`) in your `package.json` to prevent unexpected breaking changes on patch/minor updates. Review release notes carefully when upgrading.
Ensure `APP_ORIGIN` is correctly set in your environment variables for the Better Auth server. For Node.js, this typically means `process.env.APP_ORIGIN`.
Verify that `process.env.WEBHOOK_SECRET` in your `convex/http.ts` matches the `secret` configured in the `syncPlugin` on your Better Auth server. Also, check for clock skew between the Better Auth server and Convex.
Double-check that `authClient` from `@/lib/auth-client` is correctly configured and that `ConvexClientProvider` is wrapping your application's components at a high level in the React tree.