Use and adapt start-kit
Use and adapt start-kit: A Next.js starter with Better Auth authentication, database integration, and reusable interface components.
Use the documented interfaces and source layout for start-kit. The sections below retain the README’s examples and configuration details.
Authentication
Features
- Email/password authentication
- Session management
- Protected routes
- Password reset flow
Usage
The authentication system is built with Better Auth and Zustand. Use the useAuth hook in your components:
import { useAuth } from "@/hooks/use-auth";
function MyComponent() {
const { user, isAuthenticated, login, logout } = useAuth();
if (!isAuthenticated) {
return <div>Please log in</div>;
}
return <div>Welcome, {user?.name}!</div>;
}Protected Routes
Use the AuthWrapper component to protect routes:
import { AuthWrapper } from "@/components/auth/auth-wrapper";
export default function ProtectedPage() {
return (
<AuthWrapper>
<div>This content is protected</div>
</AuthWrapper>
);
}UI Components
This project uses Shadcn UI components. All components are located in components/ui/:
- Button
- Input
- Card
- Alert
- Avatar
- Separator
- Skeleton
- And more...
To add new components:
npx shadcn@latest add [component-name]Database
MongoDB Connection
The project uses Mongoose for MongoDB connection. The connection is handled in lib/db/mongoose.ts with connection pooling.
User Model
The User model is defined in models/User.ts:
interface IUser {
email: string;
name: string;
emailVerified?: boolean;
image?: string;
createdAt: Date;
updatedAt: Date;
}Configuration
Environment Variables
| Variable | Description | Required | Default |
|---|---|---|---|
MONGODB_URI | MongoDB connection string (without database name) | Yes | - |
MONGODB_DB_NAME | MongoDB database name | No | Cluster0 |
BETTER_AUTH_SECRET | Secret key for Better Auth (min 32 chars) | Yes | - |
BETTER_AUTH_URL | Base URL for Better Auth (server) | Yes | - |
NEXT_PUBLIC_BETTER_AUTH_URL | Base URL for Better Auth (client) | Yes | - |
Better Auth Configuration
Better Auth is configured in lib/auth/config.ts. The configuration includes:
- MongoDB adapter
- Email/password provider
- Session management
Commands in the root manifest
The captured package.json declares the following scripts. Run them from the directory containing that manifest.
| Command | Script |
|---|---|
npm run dev | next dev |
npm run build | next build |
npm run start | next start |
npm run lint | eslint |
Troubleshooting
MongoDB Connection Issues
- Ensure MongoDB is running
- Check
MONGODB_URIin.env.local - Verify network connectivity for cloud databases
Authentication Errors
- Verify
BETTER_AUTH_SECRETis set (min 32 characters) - Check that
BETTER_AUTH_URLmatches your domain - Ensure MongoDB connection is working
Build Errors
- Clear
.nextfolder:rm -rf .next - Reinstall dependencies:
rm -rf node_modules && npm install - Check TypeScript errors:
npm run lint
Source and help
The catalog identifies the license as MIT. Read the repository license before redistributing source or assets.
Source captured: 2026-10-11
