-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The lookupToken function doesn't seem to receive the cookie options. #319
Comments
Thanks for reporting! Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that. |
I too am seeing this issue. I'm using @fastify/cookie with @fastify/jwt, and the cookies property is never initialized. I believe this is fallout from a change in @fastify/cookie #248 |
In that PR, there is no change to the behavior of the function |
workaround for now: const SESSION_COOKIE_NAME = 'whatever';
export async function verifyJwt(
this: FastifyInstance,
req: FastifyRequest,
rep: FastifyReply,
) {
try {
// biome-ignore lint/suspicious/noExplicitAny: workaround
(req as any).cookies = {
session: req.headers.cookie
?.split('; ')
.find((row) => row.startsWith(SESSION_COOKIE_NAME))
?.split('=')[1],
};
await req.jwtVerify();
} catch (err) {
return rep.send(this.httpErrors.unauthorized('invalid token'));
}
} |
Prerequisites
Fastify version
4.24.3
Plugin version
No response
Node.js version
20.10
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
16.2
Description
When setting the plugin to only look for the token in the cookies and with the cookieName specified it fails to look there.
While checking the lookupToken function it seems that there is the following test which will fail every time as the cookie variable is not defined.
Steps to Reproduce
Try to define the options as below:
Expected Behavior
To find the token in the request.cookies[JWT_COOKIE].
The text was updated successfully, but these errors were encountered: