Add server, routes, views, CLI, CSS, and integration tests
- Server factory with Fastify plugins (JWT, cookie, multipart, formbody, static) - Auth middleware: requireAuth preHandler (401 for API, redirect for pages) - Auth API routes: POST /api/v1/auth/login, POST /api/v1/auth/logout - File API routes: GET/POST /api/v1/files, DELETE /api/v1/files/:id - Page routes: /, /login, /logout, /upload, /files, /files/:id/delete, /f/:id, /f/:id/raw - HTML views: layout, login, upload, file-list, file-view, not-found - CLI register-user script - public/style.css dark theme - Test helpers: createTestApp, loginAs, buildMultipart - Integration tests for auth API, file API, and page routes (51 tests passing) - Update CLAUDE.md with red/green TDD and commit instructions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
15
src/middleware/auth.ts
Normal file
15
src/middleware/auth.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { FastifyRequest, FastifyReply } from 'fastify';
|
||||
|
||||
export async function requireAuth(request: FastifyRequest, reply: FastifyReply): Promise<void> {
|
||||
try {
|
||||
await request.jwtVerify();
|
||||
} catch {
|
||||
// API routes get 401, page routes get redirect
|
||||
const isApi = request.url.startsWith('/api/');
|
||||
if (isApi) {
|
||||
reply.status(401).send({ error: 'Unauthorized' });
|
||||
} else {
|
||||
reply.redirect('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user