Better Auth library patterns. Only for projects using better-auth package.
Implements authentication using Better Auth when the project includes the `better-auth` package. Triggers on `better-auth` dependency detection to configure the auth instance, set up Drizzle adapter, and generate client hooks for sign-in/out.
/plugin marketplace add settlemint/agent-marketplace/plugin install devtools@settlemintThis skill inherits all available tools. When active, it can use any tool Claude has access to.
<mcp_first> CRITICAL: Use OctoCode to search Better Auth patterns.
MCPSearch({ query: "select:mcp__plugin_devtools_octocode__githubSearchCode" })
// Better Auth server setup
mcp__octocode__githubSearchCode({
keywordsToSearch: ["betterAuth", "database", "socialProviders"],
owner: "better-auth",
repo: "better-auth",
path: "packages/better-auth/src",
mainResearchGoal: "Understand Better Auth server configuration",
researchGoal: "Find auth instance setup patterns",
reasoning: "Need current API for Better Auth setup",
});
// Passkey configuration
mcp__octocode__githubSearchCode({
keywordsToSearch: ["passkey", "webauthn", "authenticator"],
owner: "better-auth",
repo: "better-auth",
path: "packages",
mainResearchGoal: "Understand passkey implementation",
researchGoal: "Find passkey plugin patterns",
reasoning: "Need current API for passkey authentication",
});
// React hooks
mcp__octocode__githubSearchCode({
keywordsToSearch: ["useSession", "signIn", "signOut"],
owner: "better-auth",
repo: "better-auth",
path: "packages/better-auth/src/client",
mainResearchGoal: "Understand Better Auth React hooks",
researchGoal: "Find client-side auth patterns",
reasoning: "Need current API for React integration",
});
</mcp_first>
<quick_start> Server setup (lib/auth/index.ts):
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { passkey } from "@better-auth/passkey";
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),
emailAndPassword: {
enabled: true,
},
plugins: [passkey()],
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
},
});
export type Session = typeof auth.$Infer.Session;
Client setup:
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient({
baseURL: process.env.NEXT_PUBLIC_APP_URL,
});
export const { useSession, signIn, signOut } = authClient;
Usage in components:
function LoginButton() {
const { data: session, isPending } = useSession();
if (isPending) return <Spinner />;
if (session) {
return <button onClick={() => signOut()}>Sign Out</button>;
}
return (
<button onClick={() => signIn.email({ email, password })}>Sign In</button>
);
}
</quick_start>
<plugins> | Plugin | Purpose | |--------|---------| | `passkey` | WebAuthn/passkey authentication | | `organization` | Multi-tenant organizations | | `twoFactor` | 2FA with TOTP | | `magicLink` | Email magic links | | `anonymous` | Anonymous sessions | </plugins><social_providers>
socialProviders: {
google: { clientId, clientSecret },
github: { clientId, clientSecret },
discord: { clientId, clientSecret },
apple: { clientId, clientSecret, teamId, keyId, privateKey },
}
</social_providers>
<constraints> **Required:** - Use Drizzle adapter for database - Set `BETTER_AUTH_SECRET` env variable - Generate auth schema: `bunx @better-auth/cli generate` - Handle session in API routes via `auth.api.getSession`Security:
bun run db:generate bun run db:migrate
</commands>
<success_criteria>
- [ ] OctoCode searched for current patterns
- [ ] Auth instance configured with database
- [ ] Client hooks set up correctly
- [ ] Protected routes check session
- [ ] Social providers configured (if needed)
</success_criteria>
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.