All files / apps/server/src index.ts

100% Statements 43/43
100% Branches 8/8
100% Functions 0/0
100% Lines 43/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 6x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 6x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x  
import { Context, Hono } from "hono";
import { cors } from "hono/cors";
 
import { OTPUtils } from "./utils/otp";
 
const app = new Hono();
 
app.use("*", cors());
 
app.post("/api/otp/generate", async (c: Context) => {
  try {
    const { issuer, label, algorithm, digits, period, secret } =
      await c.req.json<{
        issuer?: string;
        label?: string;
        algorithm?: string;
        digits?: number;
        period?: number;
        secret: string;
      }>();
 
    if (!secret) {
      return c.json({ error: "Missing secret" }, 400);
    }
 
    const token = OTPUtils.generateTOTP({
      issuer,
      label,
      algorithm,
      digits,
      period,
      secret,
    });
 
    return c.json({ token, timestamp: new Date().toISOString() });
  } catch (error) {
    const errorMessage =
      error instanceof Error ? error.message : "Internal server error";
    return c.json({ error: errorMessage }, 500);
  }
});
 
export default app;