I’m building a API using Fastify and @fastify/jwt and I’m having trouble specifing which secret I’m going to use to create and verify a JWT.
I have 2 different JWT’s: “refresh-token” and “token”
for “refresh-token” I’m gonna use a JWT_REFRESH_SECRET, and for “token” I’m gonna use “JWT_SECRET”
Here is my “app.ts”, where I configure my fastifyJwt:
app.register(fastifyJwt, { secret: env.JWT_SECRET, cookie:{ cookieName: 'refreshToken', signed: false }, sign: { expiresIn: '10m' } })
using
await request.jwtVerify({ onlyCookie: true })
How can I specify the secret I’m gonna use to decode this JWT?
const token = await reply.jwtSign({ sub: request.user.sub, })
And to create the JWT, how can I specify the secret to create it?
I tried using
await request.jwtVerify({ onlyCookie: true, secret: env.JWT_REFRESH_SECRET })
but I always got an Error
”
No overload matches this call.
Overload 1 of 5, ‘(options?: FastifyJwtVerifyOptions | undefined): Promise’, gave the following error.
Object literal may only specify known properties, and ‘onlyCookie’ does not exist in type ‘FastifyJwtVerifyOptions’.
Overload 2 of 5, ‘(callback: VerifierCallback): void’, gave the following error.
Object literal may only specify known properties, and ‘onlyCookie’ does not exist in type ‘VerifierCallback’.
Overload 3 of 5, ‘(options?: Partial | undefined): Promise’, gave the following error.
Object literal may only specify known properties, and ‘secret’ does not exist in type ‘Partial’.ts(2769)
(method) FastifyRequest<RouteGenericInterface, RawServerDefault, IncomingMessage, FastifySchema, FastifyTypeProviderDefault, unknown, FastifyBaseLogger, ResolveFastifyRequestType<…>>.jwtVerify(options?: FastifyJwtVerifyOptions | undefined): Promise (+4 overloads)
“