Skip to content

secondsky/claude-skills / plugins/better-auth/skills/better-auth

better-auth

Verified

Skill for integrating Better Auth - comprehensive TypeScript authentication framework for Cloudflare D1, Next.js, Nuxt, and 15+ frameworks. Use when adding auth, encountering D1 adapter errors, or implementing OAuth/2FA/RBAC features.

FileKindSize
SKILL.mdskill md29.2 KB
assets/auth-flow-diagram.mdmarkdown24.0 KB
references/advanced-features.mdmarkdown14.7 KB
references/cloudflare-worker-drizzle.tsscript12.7 KB
references/cloudflare-worker-kysely.tsscript9.7 KB
references/configuration-guide.mdmarkdown10.7 KB
references/database-schema.tsscript10.8 KB
references/databases/mongodb.mdmarkdown5.3 KB
references/databases/mysql.mdmarkdown6.8 KB
references/databases/postgresql.mdmarkdown8.4 KB
references/error-catalog.mdmarkdown12.9 KB
references/framework-comparison.mdmarkdown8.2 KB
references/frameworks/api-frameworks.mdmarkdown9.2 KB
references/frameworks/expo-mobile.mdmarkdown8.7 KB
references/frameworks/nextjs.mdmarkdown5.4 KB
references/frameworks/nuxt.mdmarkdown6.0 KB
references/frameworks/remix.mdmarkdown6.1 KB
references/frameworks/sveltekit.mdmarkdown6.3 KB
references/integrations/electron.mdmarkdown8.2 KB
references/migration-guide-1.4.0.mdmarkdown23.2 KB
references/migration-guide-1.5.0.mdmarkdown6.3 KB
references/nextjs/README.mdmarkdown1.1 KB
references/nextjs/postgres-example.tsscript4.0 KB
references/plugins/api-tokens.mdmarkdown10.0 KB
references/plugins/authentication.mdmarkdown9.2 KB
references/plugins/enterprise.mdmarkdown9.1 KB
references/plugins/payments.mdmarkdown8.0 KB
references/plugins/sso.mdmarkdown9.4 KB
references/plugins/test-utils.mdmarkdown5.5 KB
references/react-client-hooks.tsxother12.8 KB
references/setup-guide.mdmarkdown8.9 KB
references/v1.4-features.mdmarkdown8.2 KB
references/v1.5-features.mdmarkdown11.0 KB
references/v1.6-features.mdmarkdown6.1 KB
scripts/generate-secret.shexecutablescript2.0 KB
scripts/setup-d1-drizzle.shexecutablescript10.2 KB
scripts/test-auth-health.shexecutablescript2.1 KB
scripts/validate-config.tsscript4.3 KB

scripts/validate-config.ts

View on GitHub
#!/usr/bin/env bun
/**
 * Validate better-auth configuration
 * Usage: bun run validate-config.ts [path-to-auth.ts]
 *
 * Checks for common configuration mistakes before deployment.
 */

import { existsSync, readFileSync } from "fs";
import { resolve } from "path";

const REQUIRED_FIELDS = ["secret", "database"];
const COMMON_MISTAKES = [
  { pattern: /d1Adapter/i, message: "d1Adapter doesn't exist - use drizzleAdapter(db) for Drizzle or new Kysely({ dialect: new D1Dialect() }) for Kysely" },
  { pattern: /forgetPassword/i, message: "forgetPassword is deprecated - use requestPasswordReset (v1.4.0+)" },
  { pattern: /require\s*\(/i, message: "CommonJS require() detected - better-auth v1.4.0+ is ESM-only" },
];

// Placeholder / weak-secret detection for BETTER_AUTH_SECRET.
// We only flag values that appear inline in the config; if the secret is
// sourced from process.env (the recommended pattern), the real value lives
// outside this file and we cannot judge it here.
const PLACEHOLDER_PATTERN = /^(your[-_]?|changeme|placeholder|xxx+|test|example|default)/i;
const MIN_SECRET_LENGTH = 16;

/**
 * Extract an inline secret value from a `secret: "..."` or `secret: '...'`
 * assignment. Returns null when the secret is sourced from process.env or
 * not found as an inline string literal.
 */
function extractInlineSecret(content: string): string | null {
  const match = content.match(/secret\s*:\s*(['"])([^'"]+)\1/);
  return match ? match[2] : null;
}

function validateRequiredFields(content: string): string[] {
  const errors: string[] = [];
  for (const field of REQUIRED_FIELDS) {
    if (!content.includes(field)) {
      errors.push(`Missing required field: '${field}'`);
    }
  }
  return errors;
}

function validateConfig(filePath: string): { valid: boolean; errors: string[]; warnings: string[] } {
  const errors: string[] = [];
  const warnings: string[] = [];

  if (!existsSync(filePath)) {
    return { valid: false, errors: [`File not found: ${filePath}`], warnings: [] };
  }

  const content = readFileSync(filePath, "utf-8");

  // Validate required fields
  errors.push(...validateRequiredFields(content));

  // Validate BETTER_AUTH_SECRET value if it is inline in the config.
  // (When sourced from process.env the value is not visible here and we
  // cannot judge its strength.)
  const secretValue = extractInlineSecret(content);
  if (typeof secretValue === "string") {
    if (PLACEHOLDER_PATTERN.test(secretValue)) {
      errors.push(`BETTER_AUTH_SECRET appears to be a placeholder ("${secretValue}"). Set a real secret.`);
    } else if (secretValue.length < MIN_SECRET_LENGTH) {
      errors.push(`BETTER_AUTH_SECRET is too short (${secretValue.length} chars; minimum ${MIN_SECRET_LENGTH}).`);
    }
  }

  // Check for common mistakes
  for (const { pattern, message } of COMMON_MISTAKES) {
    if (pattern.test(content)) {
      errors.push(message);
    }
  }

  // Check for required imports
  if (!content.includes("betterAuth")) {
    errors.push("Missing betterAuth import");
  }

  // Check for database adapter
  if (!content.includes("drizzleAdapter") && !content.includes("prismaAdapter") && !content.includes("mongoAdapter") && !content.includes("new Kysely(")) {
    warnings.push("No database adapter detected - ensure you're using drizzleAdapter, prismaAdapter, mongoAdapter, or new Kysely()");
  }

  // Check for baseURL in production
  if (!content.includes("baseURL")) {
    warnings.push("Missing 'baseURL' - required for OAuth callbacks in production");
  }

  // Check for ESM compatibility
  if (content.includes("module.exports")) {
    errors.push("CommonJS module.exports detected - use ES module exports");
  }

  return {
    valid: errors.length === 0,
    errors,
    warnings,
  };
}

// Main execution
const configPath = process.argv[2] || "./src/auth.ts";
const resolvedPath = resolve(configPath);

console.log(`\nValidating: ${resolvedPath}\n`);

const result = validateConfig(resolvedPath);

if (result.errors.length > 0) {
  console.log("ERRORS:");
  result.errors.forEach((e) => console.log(`  - ${e}`));
}

if (result.warnings.length > 0) {
  console.log("\nWARNINGS:");
  result.warnings.forEach((w) => console.log(`  - ${w}`));
}

if (result.valid && result.warnings.length === 0) {
  console.log("Configuration looks good!");
}

process.exit(result.valid ? 0 : 1);
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall