@otp-service/fastify
v0.1.2
Published
Fastify route helpers for OTP generate and verify flows.
Downloads
335
Readme
@otp-service/fastify
Fastify route handlers for OTP generate and verify, plus a small error handler helper, using an @otp-service/core OtpService.
ESM only · Node.js ≥ 22 · License: MIT
Install
npm install @otp-service/fastify @otp-service/core fastifyfastify is a peer dependency (^5.0.0).
Usage
import Fastify from "fastify";
import {
createGenerateChallengeHandler,
createVerifyChallengeHandler,
fastifyOtpErrorHandler
} from "@otp-service/fastify";
const app = Fastify();
app.post("/otp/generate", createGenerateChallengeHandler({ otpService }));
app.post("/otp/verify", createVerifyChallengeHandler({ otpService }));
app.setErrorHandler(fastifyOtpErrorHandler);Request bodies
Same contract as Express helpers: generate expects channel, purpose, recipient; verify expects challengeId, otp. Optional mapBody customizes parsing.
Exports
| Export | Purpose |
|--------|---------|
| createGenerateChallengeHandler | Fastify route handler |
| createVerifyChallengeHandler | Fastify route handler |
| fastifyOtpErrorHandler | Maps validation errors to HTTP responses |
| FastifyOtpValidationError | Validation error type |
Related packages
@otp-service/core@otp-service/express— same HTTP semantics on Express- Guide: docs/guides/frameworks/fastify.md
