Set up Fastify + TypeScript + Drizzle ORM backend with: - Database schema (7 tables: users, categories, questions, knowledge_cards, user_progress, skill_tree, user_chapter_progress) - JWT auth middleware + admin token auth - Route structure for auth, quiz, progress, gamification, payment, and admin - Service stubs for Phase 1b implementation - Zod-validated env config, custom error classes
19 lines
575 B
TypeScript
19 lines
575 B
TypeScript
import { FastifyInstance } from 'fastify';
|
|
import { config } from '../../utils/config.js';
|
|
|
|
export async function adminAuthRoutes(app: FastifyInstance): Promise<void> {
|
|
app.post('/admin/auth', async (request, reply) => {
|
|
const { token } = request.body as { token: string };
|
|
|
|
if (token !== config.ADMIN_TOKEN) {
|
|
return reply.status(401).send({
|
|
success: false,
|
|
data: null,
|
|
error: { code: 'UNAUTHORIZED', message: 'Invalid admin token' },
|
|
});
|
|
}
|
|
|
|
return { success: true, data: { authenticated: true }, error: null };
|
|
});
|
|
}
|