Email sign-in takes a long time to execute

Hey good people! I've been working on a better-auth project with hono as a backend server hosted on cloudflare workers (with drizzle + d1 as my db) I've noticed that sign-in requests consistently take almost 5 seconds to execute, and I was wondering if this is to be expected due to using drizzle, and if it's not, how could I try to debug this? Thanks for any shared tips! Project is open source if you want to check the whole thing, but my auth config file looks like this:
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import type { Context } from "hono";
import type { AppBindings } from ".";
import getDb from "./db";
import * as schema from "./schema";

export function getAuth(c: Context<AppBindings>) {
const isProduction = c.env.ENVIRONMENT === "production";
const trustedOrigins = isProduction
? ["https://app.social-relay.com"]
: ["http://localhost:3001"];

return betterAuth({
trustedOrigins,
basePath: "/auth",
baseUrl: c.env.BETTER_AUTH_URL,
database: drizzleAdapter(getDb(c), {
schema,
provider: "sqlite",
usePlural: true,
}),
emailAndPassword: {
enabled: true
},
socialProviders: {
google: {
clientId: c.env.AUTH_GOOGLE_CLIENT_ID,
clientSecret: c.env.AUTH_GOOGLE_CLIENT_SECRET,
},
},
advanced: {
crossSubDomainCookies: {
enabled: isProduction,
domain: ".social-relay.com",
},
},
});
}
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import type { Context } from "hono";
import type { AppBindings } from ".";
import getDb from "./db";
import * as schema from "./schema";

export function getAuth(c: Context<AppBindings>) {
const isProduction = c.env.ENVIRONMENT === "production";
const trustedOrigins = isProduction
? ["https://app.social-relay.com"]
: ["http://localhost:3001"];

return betterAuth({
trustedOrigins,
basePath: "/auth",
baseUrl: c.env.BETTER_AUTH_URL,
database: drizzleAdapter(getDb(c), {
schema,
provider: "sqlite",
usePlural: true,
}),
emailAndPassword: {
enabled: true
},
socialProviders: {
google: {
clientId: c.env.AUTH_GOOGLE_CLIENT_ID,
clientSecret: c.env.AUTH_GOOGLE_CLIENT_SECRET,
},
},
advanced: {
crossSubDomainCookies: {
enabled: isProduction,
domain: ".social-relay.com",
},
},
});
}
No description
2 Replies
bekacru
bekacru2mo ago
The main thing you need to do is that index your db. Make sure you've indexed relevant fields. You can check optimize perf giude in the docs
Kelion
KelionOP2mo ago
I'll definitely check it out! Don't think that was the issue on this case thought, since my db was empty and I only had better-auth's tables. Initializing a auth instance apparently helped? even though this is running on cf workers, which doesn't make much sense in my head, but api times are now ~600ms which is ok
No description

Did you find this page helpful?