@orveth/jwt
Symmetric HS256 JWT helpers built on jose. Suitable for service-to-service or first-party session tokens where you control the signing secret.
Exports
signJwt(claims, secret, options?)— compact HS256 token string.verifyJwt(token, secret, options?)— returns claims; throwsHttpError401 (ORVETH_JWT_INVALID) on failure.verifyBearerJwt(header, secret, options?)— parsesAuthorization: Bearerthen verifies.extractBearerToken(header)/requireBearerToken(header)— header parsing only.
Example
import { signJwt, verifyBearerJwt } from "@orveth/jwt";
import { Orveth } from "orveth";
const secret = process.env.JWT_SECRET!;
const app = new Orveth();
app.post("/login", async (ctx) => {
const token = await signJwt({ sub: "user-1" }, secret, { expiresIn: "15m" });
return ctx.ok({ token });
});
app.get("/me", async (ctx) => {
const user = await verifyBearerJwt<{ sub: string }>(ctx.request.headers.authorization, secret);
return ctx.ok({ sub: user.sub });
});