auth-schema-generator
Generate Better Auth user schema configuration with custom additional fields for user profiles. Use when implementing authentication, user profiles, or extending user data models with Better Auth. Automatically generates TypeScript types and database schema.
When & Why to Use This Skill
The Auth Schema Generator is a specialized Claude skill designed to streamline the implementation of Better Auth by automating the creation of user schema configurations. It enables developers to seamlessly integrate custom profile fields—such as user preferences, professional metadata, and onboarding data—while automatically generating the corresponding TypeScript types and database schemas. This ensures end-to-end type safety and significantly reduces the manual boilerplate required for robust authentication systems.
Use Cases
- Case 1: Rapidly bootstrapping a new web application with a fully configured Better Auth system, including custom user data models and database migrations.
- Case 2: Extending existing user profiles with specialized fields like job titles, department info, or personalized settings without manual type definition.
- Case 3: Implementing complex user onboarding flows by generating schemas for background questionnaires and syncing them with the authentication layer.
- Case 4: Maintaining a single source of truth for user data by synchronizing database schema requirements with frontend TypeScript interfaces for improved developer experience.
| name | auth-schema-generator |
|---|---|
| description | Generate Better Auth user schema configuration with custom additional fields for user profiles. Use when implementing authentication, user profiles, or extending user data models with Better Auth. Automatically generates TypeScript types and database schema. |
| allowed-tools | write_to_file, view_file, replace_file_content |
Auth Schema Generator
Generate Better Auth user schema configurations with custom additional fields for authentication systems.
When to Use
Use this skill when:
- Implementing Better Auth in a new project
- Adding custom user profile fields (background info, preferences, settings)
- Extending user data model with questionnaire responses
- Setting up authentication with personalized user data
Instructions
Step 1: Identify Required Fields
Determine what additional user data you need:
- User preferences (theme, language, notifications)
- Profile information (job title, department, bio)
- Background data (experience levels, skills, interests)
- System metadata (onboarding status, last login)
Step 2: Generate Schema Configuration
Create Better Auth configuration in src/lib/auth.ts:
export const auth = betterAuth({
database: pool,
emailAndPassword: {
enabled: true,
},
user: {
additionalFields: {
// Generated fields based on requirements
fieldName: {
type: "string",
required: true,
defaultValue: "default",
},
},
},
});
Step 3: Generate TypeScript Types
Export inferred types for type safety:
export type Session = typeof auth.$Infer.Session;
export type User = typeof auth.$Infer.User;
Step 4: Create Interface Definitions
Generate TypeScript interfaces for use in components:
interface UserProfile {
[fieldName]: string;
// Additional fields...
}
Example: Background Questionnaire
For a learning platform with user background profiling:
Input: Need to track software experience, AI/ML familiarity, hardware knowledge, learning goals
Generated Schema:
user: {
additionalFields: {
softwareExperience: {
type: "string",
required: true,
defaultValue: "beginner"
},
aiMlFamiliarity: {
type: "string",
required: true,
defaultValue: "none"
},
hardwareExperience: {
type: "string",
required: true,
defaultValue: "none"
},
learningGoals: {
type: "string",
required: true,
defaultValue: "hobby"
},
programmingLanguages: {
type: "string",
required: false,
defaultValue: ""
}
}
}
Generated Interface:
interface BackgroundProfile {
softwareExperience: string;
aiMlFamiliarity: string;
hardwareExperience: string;
learningGoals: string;
programmingLanguages?: string;
}
Field Types Supported
string: Text fieldsnumber: Numeric valuesboolean: True/false flagsdate: Timestamps
Best Practices
- Use Descriptive Names:
softwareExperiencenotexp - Set Sensible Defaults: Provide default values for required fields
- Mark Optional Fields: Use
required: falsefor optional data - Type Safety: Always export TypeScript types
- Validation: Validate field values in your forms before submission
Files Modified
This skill typically modifies:
src/lib/auth.ts- Better Auth configurationsrc/types/auth.ts- TypeScript type definitions (if separate file)src/hooks/useAuth.ts- Custom auth hook to use typed data
Security Considerations
- Never store sensitive data in additional fields (use separate encrypted storage)
- Validate all user input before saving to database
- Use appropriate field types for the data being stored
- Consider GDPR/privacy implications for profile data