Using drizzle pglite with better-auth

Has anyone successfully used better-auth with drizzle-pglite?
6 Replies
Ping
Ping4mo ago
I don't have a demo for you, but I'm sure other has. I might be of help however, what issue are you facing?
Cammy
CammyOP4mo ago
ah i appreciate that, im currently using tanstack start so it could be an issue with that: but i have the following drizzle-dev.config.ts:
import { defineConfig } from "drizzle-kit";

export default defineConfig({
out: "./drizzle",
schema: "./lib/server/schema/index.ts",
dialect: "postgresql",
driver: "pglite",
dbCredentials: {
url: "./dev-db",
},
});
import { defineConfig } from "drizzle-kit";

export default defineConfig({
out: "./drizzle",
schema: "./lib/server/schema/index.ts",
dialect: "postgresql",
driver: "pglite",
dbCredentials: {
url: "./dev-db",
},
});
i have the drizzle-prod.config.ts:
import { defineConfig } from "drizzle-kit";
import { env } from "~/lib/env/server";

export default defineConfig({
out: "./drizzle",
schema: "./lib/server/schema/index.ts",
breakpoints: true,
dialect: "postgresql",
dbCredentials: {
url: env.DATABASE_URL,
},
});
import { defineConfig } from "drizzle-kit";
import { env } from "~/lib/env/server";

export default defineConfig({
out: "./drizzle",
schema: "./lib/server/schema/index.ts",
breakpoints: true,
dialect: "postgresql",
dbCredentials: {
url: env.DATABASE_URL,
},
});
db.ts
import { drizzle as drizzlePostgres } from "drizzle-orm/postgres-js";
import { drizzle as drizzlePGLite } from "drizzle-orm/pglite";
import postgres from "postgres";
import { env } from "../env/server";
import * as schema from "./schema";
import { migrate } from "drizzle-orm/pglite/migrator";

export const table = schema;

function initDb() {
if (import.meta.env.PROD) {
const driver = postgres(env.DATABASE_URL);
const db = drizzlePostgres(driver, { schema });
return db;
}
return drizzlePGLite("./dev-db", { schema });
}

export const db = initDb();
import { drizzle as drizzlePostgres } from "drizzle-orm/postgres-js";
import { drizzle as drizzlePGLite } from "drizzle-orm/pglite";
import postgres from "postgres";
import { env } from "../env/server";
import * as schema from "./schema";
import { migrate } from "drizzle-orm/pglite/migrator";

export const table = schema;

function initDb() {
if (import.meta.env.PROD) {
const driver = postgres(env.DATABASE_URL);
const db = drizzlePostgres(driver, { schema });
return db;
}
return drizzlePGLite("./dev-db", { schema });
}

export const db = initDb();
what im noticing is the db is being updated, say a user signs up via google oauth, but the db isnt being updated so when i run a session check its null. If i restart the dev server the db will have the user and pass the auth check
Ping
Ping4mo ago
What do you mean by session check?
Cammy
CammyOP4mo ago
const session = await auth.api.getSession({ headers });
Ping
Ping4mo ago
Gotcha. Wait so when you restart your dev server, all of a suddden the DB has the userdata and when running getSession it all works?
Cammy
CammyOP4mo ago
yeah

Did you find this page helpful?