import { onRequest } from "firebase-functions/https"; import { requireAuth } from "../middleware/auth.js"; import { sendError } from "../middleware/errors.js"; import { register } from "../services/authService.js"; export const auth = onRequest(async (req, res) => { const path = req.path.replace(/^\/+|\/+$/g, "").split("/").pop() ?? ""; try { if (path === "register" && req.method === "POST") { const uid = await requireAuth(req); const result = await register(uid, req.body ?? {}); res.status(result.created ? 201 : 200).json(result); return; } res.status(404).json({ error: `Unknown path: /${path}` }); } catch (err) { sendError(res, err); } });