This is an example of how to use Better Auth with SvelteKit.
Implements the following features:
pnpm install
npx drizzle-kit generate --name='Better-Auth-schema'
npx drizzle-kit migrate
pnpm dev
http://localhost:5173
If you want to use a different database, say Postgres then do the following:
.env
/src/lib/server/db/index.ts
to use a Postgres database per the Drizzle documentation./src/lib/server/auth.ts
to use the postgres provider./drizzle.config.ts
to postgres.npx @better-auth/cli generate
/src/lib/server/db/schema.ts
with the generated schema./src/drizzle
npx drizzle-kit generate --name='Better-Auth-schema'
npx drizzle-kit migrate
The SvelteCookies plugin was implemented to fix this known issue. The code for the plugin was taken from this gist courtesy of @actuallyjamez
My dev server kept throwing 404 errors while using Chrome in dev mode. vite-plugin-devtools-json provided a way to prevent that.
I ran into some issues using runes with Svelte 5 and Superforms. This sveltekit-superforms issue provided guidance.