Testing strategy, code quality standards, and authentication patterns for a Next.js app with Clerk auth
Comprehensive development instructions for the HARKA project, a Next.js application using Clerk authentication. This skill provides testing strategies, code quality standards, and mandatory checks for safe development and deployment.
1. **ALWAYS test authentication logic** when making auth/routing changes
2. **VALIDATE middleware behavior** through code review and manual testing
3. **TEST build compilation** after every change: `pnpm run build`
4. **VERIFY TypeScript compilation** with no errors
5. **MANUAL verification** of key user flows on deployed app
When making auth/routing changes, manually verify:
**Unauthenticated Access:**
**Authentication Flow:**
**Navigation:**
When modifying `middleware.ts`, verify these key patterns:
```typescript
// 1. Auth page check FIRST (prevents redirect loops)
if (userId && isAuthPage(req)) {
return NextResponse.redirect(new URL('/learn/dashboard', req.url))
}
// 2. Admin route protection
if (isAdminRoute(req) && !req.nextUrl.pathname.startsWith('/admin/sign-in')) {
// Admin logic here
}
// 3. Public route allowance
if (isPublicRoute(req)) {
return NextResponse.next()
}
// 4. Protected route authentication requirement
if (!userId) {
return NextResponse.redirect(new URL('/sign-in', req.url))
}
```
1. **READ** existing code to understand patterns
2. **CHECK** if similar functionality exists
3. **PLAN** the implementation approach
4. **IDENTIFY** potential breaking changes
1. **FOLLOW** TypeScript best practices
2. **IMPLEMENT** proper error handling
3. **ADD** loading states for async operations
4. **MAINTAIN** consistent code style
5. **AVOID** introducing new dependencies without justification
1. **RUN** build: `pnpm run build`
2. **CHECK** TypeScript compilation succeeds
3. **VERIFY** no console errors in development
4. **TEST** key user flows manually
5. **DEPLOY** and verify on production URL
```bash
pnpm run build # Must pass without errors
pnpm run dev # Should start without issues
pnpm run type-check # TypeScript compilation check
pnpm run dev # Start development server
pnpm run lint # Check code quality
```
```typescript
// Correct pattern for middleware.ts:
const isPublicRoute = createRouteMatcher([
"/", "/about", "/pricing", "/contact", "/blog", "/blog/(.*)",
"/sign-in", "/sign-in/(.*)", "/sign-up", "/sign-up/(.*)",
"/login", "/signup", "/logout", "/toolkit", "/team", "/workshop"
])
const isAuthPage = createRouteMatcher([
'/sign-in', '/sign-in/(.*)', '/sign-up', '/sign-up/(.*)', '/login', '/signup'
])
// Order matters: Check auth users on auth pages FIRST
```
1. ✅ Build completes successfully (`pnpm run build`)
2. ✅ TypeScript compilation succeeds (no type errors)
3. ✅ Development server starts without errors
4. ✅ No console errors in browser during development
5. ✅ Authentication flows work on deployed app
6. ✅ All routes accessible as intended (manual verification)
7. ✅ Mobile responsiveness verified
8. ✅ Loading states implemented where needed
9. ✅ Error handling implemented
10. ✅ No sensitive data exposed in client-side code
```bash
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_publishable_key
CLERK_SECRET_KEY=your_secret_key
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/learn/dashboard
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/learn/dashboard
```
```bash
pnpm run dev # Start development server
pnpm run build # Build for production (REQUIRED before deploy)
pnpm run start # Start production server
pnpm run lint # Check code quality
pnpm run type-check # Check TypeScript types
npm run dev -- --turbo # Start with Turbo (faster)
npm run build -- --debug # Build with debug info
```
**Reliability > Features**. Always prioritize working, stable authentication over adding new features.
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/harka-project-development-guidelines/raw