Closed Fuarm closed 1 year ago
Can you provide a full reproducible code snippet?
The secret
function is not called by fast-jwt
directly but inside this library.
import Fastify, { FastifyInstance, FastifyRequest } from "fastify";
import fastifyJwt, { TokenOrHeader } from "@fastify/jwt";
const server: FastifyInstance = Fastify({
logger: true
});
server.register(fastifyJwt, {
secret: async (request: FastifyRequest | TokenOrHeader) => {
console.log(request);
return "secret";
}
});
server.get("/test", (request, reply) => {
const token = server.jwt.sign({ userId: 12 }, { expiresIn: "2h" });
reply.send(token);
});
/**
* 服务启动
* @param port 端口
*/
const startServer = async (port: number) => {
try {
await server.listen({ port });
} catch (err) {
server.log.error(err);
process.exit(1);
}
};
startServer(3000)
Function based secret is supported by the request.jwtVerify() and reply.jwtSign() methods and is called with request, token, and callback parameters.
I would say that it is a correct behavior since the document already told you function based secret only supported by the above two methods.
Prerequisites
Fastify version
4.23.2
Plugin version
7.2.1
Node.js version
16.19.1
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
13.5
Description
document example
Getting secret asynchronously in
fast-jwt
has norequest
paramSteps to Reproduce
Expected Behavior
No response