Skip to content

Commit

Permalink
Fix 'cookie' and 'secret' types (#164)
Browse files Browse the repository at this point in the history
* Add missing 'cookie' type

* remove old 'secret' type

* Add test for 'cookie' type
  • Loading branch information
paol-imi authored Aug 2, 2021
1 parent 3aa03ea commit c0c223b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion jwt.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export interface JWT {
sign: jwt.SignOptions
verify: jwt.VerifyOptions
}
secret: jwt.Secret
cookie?: {
cookieName: string,
signed: boolean
}

sign(payload: SignPayloadType, options?: jwt.SignOptions): string
sign(payload: SignPayloadType, callback: jwt.SignCallback): void
Expand Down
1 change: 1 addition & 0 deletions jwt.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ expectAssignable<object>(app.jwt)
expectAssignable<Function>(app.jwt.sign)
expectAssignable<Function>(app.jwt.verify)
expectAssignable<Function>(app.jwt.decode)
expectAssignable<FastifyJWTOptions['cookie']>(app.jwt.cookie)

app.addHook("preHandler", async (request, reply) => {
// assert request and reply specific interface merges
Expand Down
11 changes: 9 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ test('register', function (t) {
t.plan(13)

t.test('Expose jwt methods', function (t) {
t.plan(6)
t.plan(7)

const fastify = Fastify()
fastify.register(jwt, { secret: 'test' })
fastify.register(jwt, {
secret: 'test',
cookie: {
cookieName: 'token',
signed: false
}
})

fastify.get('/methods', function (request, reply) {
t.ok(request.jwtVerify)
Expand All @@ -32,6 +38,7 @@ test('register', function (t) {
t.ok(fastify.jwt.options)
t.ok(fastify.jwt.sign)
t.ok(fastify.jwt.verify)
t.ok(fastify.jwt.cookie)
})

fastify.inject({
Expand Down

0 comments on commit c0c223b

Please sign in to comment.