# Use and adapt start-kit

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:

```tsx
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:

```tsx
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:

```bash
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`:

```typescript
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](https://github.com/qentrah/start-kit/blob/HEAD/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_URI` in `.env.local`
- Verify network connectivity for cloud databases

### Authentication Errors

- Verify `BETTER_AUTH_SECRET` is set (min 32 characters)
- Check that `BETTER_AUTH_URL` matches your domain
- Ensure MongoDB connection is working

### Build Errors

- Clear `.next` folder: `rm -rf .next`
- Reinstall dependencies: `rm -rf node_modules && npm install`
- Check TypeScript errors: `npm run lint`

## Source and help

- [GitHub repository](https://github.com/qentrah/start-kit)
- [Original README](https://github.com/qentrah/start-kit/blob/master/README.md)
- [Issues and existing reports](https://github.com/qentrah/start-kit/issues)

The catalog identifies the license as **MIT**. Read the repository license before redistributing source or assets.