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 | 7x 26x 26x 1x 25x 25x 1x 1x 24x | import type { FastifyInstance } from "fastify";
import { requestOtp, OtpRateLimitError } from "../lib/otp.js";
export async function loginRoutes(app: FastifyInstance) {
// POST /login — send OTP to email
app.post<{ Body: { email: string } }>("/login", async (request, reply) => {
const { email } = request.body;
if (!email || typeof email !== "string") {
return reply.status(400).send({ error: "Email is required" });
}
try {
await requestOtp(email);
} catch (err) {
Eif (err instanceof OtpRateLimitError) {
return reply.status(429).send({ error: err.message });
}
throw err;
}
return { message: "OTP sent to your email" };
});
}
|