Betterauth is Slow?
import { products, favorites } from "@/db/schema";
import { useDrizzle } from "~/server/utils/drizzle";
import { and, count, eq, sql } from "drizzle-orm";
import { auth } from "~/server/utils/auth";
export default defineEventHandler(async (event) => {
const page = Number(getQuery(event).page || "1");
const limit = 8;
const offset = (page - 1) * limit;
console.time("Auth Decoding")
const session = await auth.api.getSession({
headers: event.headers,
});
console.timeEnd("Auth Decoding") //700ms
6 Replies
700ms on Localhost preview mode.
Please help me
You need to optimize your setup, wether using caching or using database indexes.
Learn more here: https://www.better-auth.com/docs/guides/optimizing-for-performance
Optimizing for Performance | Better Auth
A guide to optimizing your Better Auth application for performance.
thanks
Did you end up getting better performance? I'm working on Astro, and struggling with slow better-auth speed as well.
Tried enabling the session cookies, but didn't see much of a difference. Have yet to run the DB indexing yet though, hoping that speeds things up.
I ran the DB indexing, but I'm still getting like a 3 second delay just fetching the session server side.
My code:
It logs:
Over 3 seconds. Here is how auth is being initialized:
Is this typical performance?
This is not typical performance. It's very likely latency issues to your database.
There are users who can get their session using a remote DB in less than 30 ms.
I see, will investigate that. Using a Render Postgres instance.
Btw, any chance we can get Better-Auth working with Cloudflare Hyperdrive? Or are there no plans for that at the moment?