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

fix(fastify): Correct fastify options type #1488

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-avocados-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/fastify": patch
---

Pass the `ClerkFastifyOptions` to the exported fastify plugin
9 changes: 8 additions & 1 deletion packages/fastify/src/clerkPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jest.mock('./withClerkMiddleware', () => {

import { clerkPlugin } from './clerkPlugin';
import { createFastifyInstanceMock } from './test/utils';
import type { ALLOWED_HOOKS } from './types';

describe('clerkPlugin()', () => {
test('adds withClerkMiddleware as preHandler by default', () => {
Expand Down Expand Up @@ -35,7 +36,13 @@ describe('clerkPlugin()', () => {
const fastify = createFastifyInstanceMock();

expect(() => {
clerkPlugin(fastify, { hookName }, doneFn);
clerkPlugin(
fastify,
{
hookName: hookName as (typeof ALLOWED_HOOKS)[number],
},
doneFn,
);
}).toThrowError(`Unsupported hookName: ${hookName}`);
},
);
Expand Down
6 changes: 5 additions & 1 deletion packages/fastify/src/clerkPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import type { ClerkFastifyOptions } from './types';
import { ALLOWED_HOOKS } from './types';
import { withClerkMiddleware } from './withClerkMiddleware';

const plugin: FastifyPluginCallback = (instance: FastifyInstance, opts: ClerkFastifyOptions, done) => {
const plugin: FastifyPluginCallback<ClerkFastifyOptions> = (
instance: FastifyInstance,
opts: ClerkFastifyOptions,
done,
) => {
instance.decorateRequest('auth', null);
// run clerk as a middleware to all scoped routes
const hookName = opts.hookName || 'preHandler';
Expand Down