Auth migration

From SkillfulAgents/SuperAgent · View interactive version

Auth migration is an AI agent skill from the GitHub repository SkillfulAgents/SuperAgent. Add a new Better Auth plugin or feature and generate the corresponding database migration

How to use this skill

Skill file

Auth Schema Migration

When adding new Better Auth features (social logins, new plugins, etc.), follow this process to update the database schema.

Steps

  1. Update Better Auth config — add the plugin to src/shared/lib/auth/index.ts (server) and src/renderer/lib/auth-client.ts (client, if the plugin has a client component).
  1. Generate the updated Better Auth schema — create a temporary config file in the project root with a default auth export that includes all plugins:

```bash

cat > _ba-gen.ts << 'EOF'

import { betterAuth } from "better-auth"

import { admin } from "better-auth/plugins"

// import your new plugin here

import { drizzleAdapter } from "better-auth/adapters/drizzle"

import { drizzle } from "drizzle-orm/better-sqlite3"

import Database from "better-sqlite3"

const sqlite = new Database("/tmp/ba-gen-temp.db")

const db = drizzle(sqlite)

export const auth = betterAuth({

baseURL: "http://localhost:3000",

database: drizzleAdapter(db, { provider: "sqlite" }),

emailAndPassword: { enabled: true },

plugins: [admin() /* , newPlugin() */],

})

EOF

echo "y" | npx @better-auth/cli generate --config _ba-gen.ts --output _ba-schema.ts

```

  1. Merge changes into src/shared/lib/db/schema.ts — compare _ba-schema.ts with existing Better Auth tables. Look for new tables or new columns on user, session, account, verification.

Conventions to follow:

  1. Update the Drizzle adapter schema mapping in src/shared/lib/auth/index.ts if new tables were added:

```typescript

database: drizzleAdapter(db, {

provider: 'sqlite',

schema: {

user: schema.user,

session: schema.authSession,

account: schema.authAccount,

verification: schema.verification,

// newTable: schema.newTable,

},

}),

```

  1. Generate the Drizzle migration:

```bash

npx drizzle-kit generate

```

  1. Clean up temp files:

```bash

rm _ba-gen.ts _ba-schema.ts /tmp/ba-gen-temp.db

```

  1. Verify:

```bash

npm run typecheck # typecheck

npx vitest run # unit tests

```

The migration auto-applies on next app startup via migrate() in src/shared/lib/db/index.ts.

Key files

| File | Purpose |

|------|---------|

| src/shared/lib/auth/index.ts | Better Auth instance + plugin config |

| src/renderer/lib/auth-client.ts | Better Auth React client + client plugins |

| src/shared/lib/db/schema.ts | All Drizzle table definitions (including Better Auth tables) |

| src/shared/lib/db/index.ts | DB init + auto-migration on startup |

| src/shared/lib/db/migrations/ | Generated SQL migration files |

| drizzle.config.ts | Drizzle Kit config (points to schema + migrations) |

Important notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.