-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Change decorator name #229
Conversation
Changed decorator name to avoid conflict with @fastify/passport plugin using the same decorator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend making it configurable instead of this semver hard change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a unit test?
AS @jsumners said, make it configurable.
Done, hope it's ok now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add docs in the readme?
jwt.js
Outdated
@@ -142,9 +142,10 @@ function fastifyJwt (fastify, options, next) { | |||
let jwtDecodeName = 'jwtDecode' | |||
let jwtVerifyName = 'jwtVerify' | |||
let jwtSignName = 'jwtSign' | |||
const jwtDecoratorName = process.env.JWT_DECORATOR_NAME || 'user' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use an option to the plugin, not an env variable.
@@ -2714,3 +2714,23 @@ test('global user options should not be modified', async function (t) { | |||
t.equal(fastify.jwt.options.sign.notBefore, '4 hours') | |||
t.equal(fastify.jwt.options.verify.maxAge, 2000) | |||
}) | |||
|
|||
test('decorator name should work after being changed in the options', async function (t) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is missing an assertion that the custom decorator name is present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I included new tests asserting the new decorator name. Also updated the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dammit. Stupid phone client never sent this review.
const token = JSON.parse(signResponse.payload).token | ||
t.ok(token) | ||
t.ok(fastify.jwt.options.decoratorName) | ||
t.equal(fastify.jwt.options.decoratorName, decoratorName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good assertion. But there really should be one that verifies the decoration on the request object.
Changed decorator name to avoid conflict with @fastify/passport plugin using the same decorator
Checklist
npm run test
andnpm run benchmark
and the Code of conduct