Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b510c46
update doc
jycouet Jan 27, 2026
b294f59
external doc
jycouet Jan 27, 2026
c8a0745
switch to better-auth test
jycouet Jan 27, 2026
5c7029c
add hidden option
jycouet Jan 27, 2026
b566b48
preparing
jycouet Jan 27, 2026
e8f38aa
full client
jycouet Jan 27, 2026
f68d3ae
full client
jycouet Jan 27, 2026
4e20779
cookie
jycouet Jan 27, 2026
8729924
going server & enhance
jycouet Jan 27, 2026
da8cadb
update snap
jycouet Jan 27, 2026
c1e9896
easy win
jycouet Jan 27, 2026
7080607
some fixes & Workaround for JSDoc projects
jycouet Jan 27, 2026
28dcd96
clean
jycouet Jan 27, 2026
7af3455
next step using the right pm!
jycouet Jan 27, 2026
e96ff4f
update msg
jycouet Jan 27, 2026
3783437
format :(
jycouet Jan 27, 2026
5e00385
fix order
jycouet Jan 28, 2026
211616e
like this maybe?
jycouet Jan 28, 2026
34a92e6
full server
jycouet Jan 28, 2026
23d17c5
BETTER_AUTH_SECRET generated by default
jycouet Jan 28, 2026
18d6be1
update env & flat files
jycouet Jan 28, 2026
c120a3e
look good with flat
jycouet Jan 28, 2026
9454388
tests are passing also in turso
jycouet Jan 28, 2026
0d7fb81
move dizzle to use a task as an example
jycouet Jan 28, 2026
7a30da0
update
jycouet Jan 28, 2026
14f46d4
add github
jycouet Jan 28, 2026
13f4afd
demos on
jycouet Jan 28, 2026
71f8f98
envs & github
jycouet Jan 28, 2026
94eeade
update snap :)
jycouet Jan 28, 2026
ff788c3
we should remove lucia?
jycouet Jan 28, 2026
e2af0c5
remove lucia
jycouet Jan 28, 2026
89a638b
fixing types for addon config in tests
jycouet Jan 30, 2026
8724619
better .env stuff
jycouet Jan 30, 2026
d355ff7
.env
jycouet Jan 30, 2026
ada67d5
export *
jycouet Jan 30, 2026
c75baec
w00t
jycouet Jan 30, 2026
218afbf
-
jycouet Jan 30, 2026
80f7fcb
refacto env
jycouet Jan 30, 2026
4a9da2a
remove old comment
jycouet Feb 5, 2026
893411c
better-auth CLI was fixed
jycouet Feb 5, 2026
ca195df
no demo is possible
jycouet Feb 5, 2026
1538989
flat to text
jycouet Feb 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-terms-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

feat(add): `better-auth` is now an official addon
5 changes: 5 additions & 0 deletions .changeset/cold-insects-cut.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': minor
---

remove: `lucia` from official addons in favor of `better-auth`
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
packages/sv/lib/cli/tests/snapshots/*
packages/sv/lib/cli/tests/snapshots/*
packages/sv/lib/**/tests/**/output.ts
17 changes: 13 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,25 @@ pnpm test

### Debugging

Example of how to debug an addon failing test. Once, you ran the test command, you will have a directory in `.test-output` with the test id. A good starting point is to `cd` into the failing tests dir. Proceed to `build` it. Then `preview` it. From here you will have increased information to help in the debug process. E.g.:
Example of how to debug an addon failing test. Once you run the test command, you will have a directory in `.test-output` with the test id. A good starting point is to `cd` into the failing tests dir and run the app directly. E.g.:

```sh
pnpm test --project addons tailwind # to debug the tailwind addon failing test
# Each test is a standalone app
cd .test-output/addons/[addon-test]/[test-id]
pnpm test --project addons better-auth # Run the failing test first

# Each test generates a standalone app in .test-output
cd packages/sv/.test-output/addons/better-auth/default-kit-ts

# Option 1: Run dev server for interactive debugging
pnpm dev
# Open http://localhost:5173 and use browser DevTools to inspect

# Option 2: Build and preview (matches production behavior)
pnpm build
pnpm preview
```

Using dev mode with browser DevTools is often the fastest way to debug UI issues - you can inspect network requests, console errors, and the DOM directly. Once you identify the issue, fix it in the addon source (`packages/sv/lib/addons/[addon].ts`) and re-run the test.

### Update snapshots

Some snapshots are testing the output of `sv` directly from the generated binary. They are located in `packages/sv/lib/cli/tests/snapshots`. Make sure to generate a new binary before updating these snapshots.
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/20-commands/20-sv-add.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ Prevents installing dependencies

## Official add-ons

- [`better-auth`](better-auth)
- [`devtools-json`](devtools-json)
- [`drizzle`](drizzle)
- [`eslint`](eslint)
- [`lucia`](lucia)
- [`mcp`](mcp)
- [`mdsvex`](mdsvex)
- [`paraglide`](paraglide)
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/30-add-ons/05-drizzle.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ npx sv add drizzle

- a setup that keeps your database access in SvelteKit's server files
- an `.env` file to store your credentials
- compatibility with the Lucia auth add-on
- compatibility with the Better Auth add-on
- an optional Docker configuration to help with running a local database

## Options
Expand Down
26 changes: 0 additions & 26 deletions documentation/docs/30-add-ons/15-lucia.md

This file was deleted.

34 changes: 34 additions & 0 deletions documentation/docs/30-add-ons/16-better-auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: better-auth
---

[Better Auth](https://www.better-auth.com/) is a framework-agnostic authentication library for TypeScript.

## Usage

```sh
npx sv add better-auth
```

## What you get

- a complete auth setup for SvelteKit with Drizzle as the database adapter
- email/password authentication enabled by default
- optional demo registration and login pages

## Options

### demo

Which demo pages to include. Available values: `password` (Email & Password), `github` (GitHub OAuth).

```sh
# Email & Password only (default)
npx sv add better-auth="demo:password"

# GitHub OAuth only
npx sv add better-auth="demo:github"

# Both Email & Password and GitHub OAuth
npx sv add better-auth="demo:password,github"
```
10 changes: 8 additions & 2 deletions packages/sv/lib/addons/_engine/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ export type InstallOptions<Addons extends AddonMap> = {
packageManager?: PackageManager;
};

export type AddonMap = Record<string, Addon<any>>;
export type AddonMap = Record<string, Addon<any, any>>;

type AddonById<Addons extends AddonMap, Id extends string> = Extract<
Addons[keyof Addons],
{ id: Id }
>;

export type OptionMap<Addons extends AddonMap> = {
[K in keyof Addons]: Partial<OptionValues<Addons[K]['options']>>;
[Id in Addons[keyof Addons]['id']]: Partial<OptionValues<AddonById<Addons, Id>['options']>>;
};

export async function add<Addons extends AddonMap>({
Expand Down
6 changes: 3 additions & 3 deletions packages/sv/lib/addons/_engine/official.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Addon, AddonDefinition } from '../../core.ts';
import betterAuth from '../better-auth.ts';
import devtoolsJson from '../devtools-json.ts';
import drizzle from '../drizzle.ts';
import eslint from '../eslint.ts';
import lucia from '../lucia.ts';
import mcp from '../mcp.ts';
import mdsvex from '../mdsvex.ts';
import paraglide from '../paraglide.ts';
Expand All @@ -22,7 +22,7 @@ type OfficialAddons = {
sveltekitAdapter: Addon<any>;
devtoolsJson: Addon<any>;
drizzle: Addon<any>;
lucia: Addon<any>;
betterAuth: Addon<any>;
mdsvex: Addon<any>;
paraglide: Addon<any>;
storybook: Addon<any>;
Expand All @@ -40,7 +40,7 @@ export const officialAddons: OfficialAddons = {
sveltekitAdapter,
devtoolsJson,
drizzle,
lucia,
betterAuth,
mdsvex,
paraglide,
storybook,
Expand Down
86 changes: 86 additions & 0 deletions packages/sv/lib/addons/_tests/better-auth/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { expect } from '@playwright/test';
import { setupTest } from '../_setup/suite.ts';
import betterAuth from '../../better-auth.ts';
import drizzle from '../../drizzle.ts';
import path from 'node:path';
import fs from 'node:fs';
import { execSync } from 'node:child_process';

const { test, testCases, prepareServer } = setupTest(
{ drizzle, betterAuth },
{
kinds: [
{
type: 'default',
options: {
drizzle: { database: 'sqlite', sqlite: 'turso' },
'better-auth': { demo: ['password', 'github'] }
}
}
],
filter: (addonTestCase) => addonTestCase.variant.includes('kit')
}
);

test.concurrent.for(testCases)('better-auth $variant', async (testCase, { page, ...ctx }) => {
const cwd = ctx.cwd(testCase);
const language = testCase.variant.includes('ts') ? 'ts' : 'js';

// Verify that we have a demo login
const loginPage = path.resolve(cwd, `src/routes/demo/better-auth/login/+page.svelte`);
expect(fs.existsSync(loginPage)).toBe(true);

// For Turso, update .env to use local SQLite file instead of remote URL
const envPath = path.resolve(cwd, '.env');
let envContent = fs.readFileSync(envPath, 'utf8');
envContent = envContent.replace(/DATABASE_URL=".*"/, 'DATABASE_URL="file:local.db"');
fs.writeFileSync(envPath, envContent, 'utf8');

// Generate auth schema using better-auth CLI
execSync('npm run auth:schema', { cwd, stdio: 'pipe' });

// Verify schema has auth tables
const schemaPath = path.resolve(cwd, `src/lib/server/db/schema.${language}`);
const schemaContent = fs.readFileSync(schemaPath, 'utf8');
expect(schemaContent).toContain('export *');
expect(schemaContent).toContain('./auth.schema');

// Push schema to DB
execSync('npm run db:push -- --force', { cwd, stdio: 'pipe' });

/** ----- BROWSER SECTION ----- */
const { url, close } = await prepareServer({ cwd, page });
ctx.onTestFinished(async () => await close());

await page.goto(`${url}demo/better-auth`);

// Verify login page loaded (contains email input)
const emailInput = page.locator('input[type="email"]');
await expect(emailInput).toBeVisible();

// Fill registration form and submit
const userName = `Test_User_${Date.now()}`;
await emailInput.fill(`${userName}@example.com`);
await page.fill('input[type="password"]', 'testpassword123');
await page.locator('input').nth(2).fill(userName);

// Click register button
await page.click('button:has-text("Register")');

// // Wait for navigation to authenticated page
await page.waitForURL(`${url}demo/better-auth`, { timeout: 3000 });

// Verify user name is displayed
await expect(page.locator('h1')).toContainText(userName);

// Reload page and verify still connected
await page.reload();
await expect(page.locator('h1')).toContainText(userName);

// Sign out
await page.click('button:has-text("Sign out")');
await page.waitForURL(`${url}demo/better-auth/login`, { timeout: 3000 });

// Verify we're logged out (email input visible again)
await expect(emailInput).toBeVisible();
});
2 changes: 1 addition & 1 deletion packages/sv/lib/addons/_tests/devtools-json/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from 'node:path';

const { test, testCases } = setupTest(
{ devtoolsJson },
{ kinds: [{ type: 'default', options: { devtoolsJson: {} } }], browser: false }
{ kinds: [{ type: 'default', options: { [devtoolsJson.id]: {} } }], browser: false }
);

test.concurrent.for(testCases)('devtools-json $variant', (testCase, ctx) => {
Expand Down
16 changes: 8 additions & 8 deletions packages/sv/lib/addons/_tests/drizzle/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export const pageServer = `
import { db } from '$lib/server/db';
import { user } from '$lib/server/db/schema.js';
import { task } from '$lib/server/db/schema.js';

export const load = async () => {
await insertUser({ name: 'Foobar', id: 0, age: 20 }).catch((err) => console.error(err));
await insertTask({ title: 'My first task', id: 0, priority: 1 }).catch((err) => console.error(err));

const users = await db.select().from(user);
const tasks = await db.select().from(task);

return { users };
return { tasks };
};

function insertUser(value) {
return db.insert(user).values(value);
function insertTask(value) {
return db.insert(task).values(value);
}
`;

Expand All @@ -20,7 +20,7 @@ export const pageComp = `
export let data;
</script>

{#each data.users as user}
<span data-testid="user">{user.id} {user.name}</span>
{#each data.tasks as task}
<span data-testid="task">{task.id} {task.title}</span>
{/each}
`;
2 changes: 1 addition & 1 deletion packages/sv/lib/addons/_tests/drizzle/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ test.concurrent.for(testCases)(
// kill server process when we're done
ctx.onTestFinished(async () => await close());

expect(page.locator('[data-testid]')).toBeTruthy();
expect(page.locator('[data-testid="task"]')).toBeTruthy();
}
}
);
29 changes: 0 additions & 29 deletions packages/sv/lib/addons/_tests/lucia/test.ts

This file was deleted.

Loading
Loading