Skip to content

How to connect Triplit to Better Auth? #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mfragale opened this issue May 21, 2025 · 10 comments
Open

How to connect Triplit to Better Auth? #362

mfragale opened this issue May 21, 2025 · 10 comments

Comments

@mfragale
Copy link

Hi, I'm trying to connect Better Auth to my Triplit DB with no success.

My auth.ts code looks like this:

import { TriplitClient } from "@triplit/client";
import { betterAuth } from "better-auth";
import { schema } from "../../triplit/schema";

const triplitClient = new TriplitClient({
  schema,
  serverUrl: process.env.NEXT_PUBLIC_TRIPLIT_SERVER_URL,
  token: process.env.NEXT_PUBLIC_TRIPLIT_TOKEN,
});

export const auth = betterAuth({
  database: triplitClient,
  emailAndPassword: {
    enabled: true,
  },
});

When I try to sign up, I get this error:

⨯ [Error [BetterAuthError]: Failed to initialize database adapter] {
 cause: undefined
}
POST /api/auth/sign-up/email 500 in 30ms
node:internal/process/promises:394
   triggerUncaughtException(err, true /* fromPromise */);
   ^

[BetterAuthError: Failed to initialize database adapter] {
 cause: undefined
}

Any idea where I've gone wrong?

@daveycodez
Copy link

You need to use a Database Adapter, I created one here: https://github.com/daveyplate/better-auth-triplit

@mfragale
Copy link
Author

mfragale commented May 27, 2025 via email

@mfragale
Copy link
Author

mfragale commented May 27, 2025 via email

@daveycodez
Copy link

Are you using Next.js?

@daveycodez
Copy link

Did you set your environment variable on Vercel dashboard for BETTER_AUTH_SECRET?

@daveycodez
Copy link

Oh, leave External JWT path blank

@mfragale
Copy link
Author

Yes, using next.js, envs on vercel all set and just now blanked the External JWT path from the Triplit dashboard, but still didn't work. Here's my codebase, if it helps:

https://github.com/mfragale/triple-better

@daveycodez
Copy link

Hey hit me up on Discord it'll be easier to help you there my username is daveycodez

I'd suggest testing your production Triplit DB on next dev locally so we can identify if it's an issue on the Vercel app or local or both

@mfragale
Copy link
Author

Sure, I've sent you a request on Discord.

@daveycodez
Copy link

I think we're good to close this issue, we got it working. Had to do with using anon key for the server side HttpClient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants