Skip to content
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

Merged
merged 5 commits into from
May 30, 2022
Merged

Change decorator name #229

merged 5 commits into from
May 30, 2022

Conversation

sergioalmela
Copy link
Contributor

@sergioalmela sergioalmela commented May 27, 2022

Changed decorator name to avoid conflict with @fastify/passport plugin using the same decorator

Checklist

Changed decorator name to avoid conflict with @fastify/passport plugin using the same decorator
Copy link
Member

@jsumners jsumners left a 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.

Copy link
Member

@mcollina mcollina left a 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.

@sergioalmela
Copy link
Contributor Author

Can you please add a unit test? AS @jsumners said, make it configurable.

Done, hope it's ok now

Copy link
Member

@mcollina mcollina left a 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'
Copy link
Member

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) {
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit e11a320 into fastify:master May 30, 2022
Copy link
Member

@jsumners jsumners left a 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)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants