Skip to content
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
15 changes: 15 additions & 0 deletions .changeset/soft-walls-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@clerk/nuxt": minor
---

Bump `@nuxt/*` dependencies to 3.16.0 and add proper typing for `event.context.auth` object in event handlers

```ts
export default eventHandler((event) => {
const { userId } = event.context.auth // auth is now typed

// ...

return { userId }
})
```
6 changes: 3 additions & 3 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
"@clerk/shared": "workspace:^",
"@clerk/types": "workspace:^",
"@clerk/vue": "workspace:^",
"@nuxt/kit": "^3.14.159",
"@nuxt/schema": "^3.14.159",
"@nuxt/kit": "^3.16.0",
"@nuxt/schema": "^3.16.0",
Comment on lines +70 to +71
Copy link
Member Author

Choose a reason for hiding this comment

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

We need to update @nuxt/kit to 3.16.0 to support proper type augmentation for event.context.auth in Nitro.

This is a non-breaking change as it only requires the updated @nuxt/kit package and works with any Nuxt version.

"h3": "^1.13.0"
},
"devDependencies": {
"nuxt": "^3.14.159",
"nuxt": "^3.16.0",
"typescript": "catalog:repo"
},
"engines": {
Expand Down
16 changes: 16 additions & 0 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
addImportsDir,
addPlugin,
addServerHandler,
addTypeTemplate,
createResolver,
defineNuxtModule,
updateRuntimeConfig,
Expand Down Expand Up @@ -97,6 +98,21 @@ export default defineNuxtModule<ModuleOptions>({
});
}

// Adds TS support for `event.context.auth` in event handlers
addTypeTemplate(
{
filename: 'types/clerk.d.ts',
getContents: () => `import type { AuthObject } from '@clerk/backend';
declare module 'h3' {
interface H3EventContext {
auth: AuthObject;
}
}
`,
},
{ nitro: true },
);

// Add auto-imports for Clerk components, composables and client utils
addImportsDir(resolver.resolve('./runtime/composables'));
addImports([
Expand Down
7 changes: 0 additions & 7 deletions packages/nuxt/src/runtime/server/clerkMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { AuthObject } from '@clerk/backend';
import type { AuthenticateRequestOptions } from '@clerk/backend/internal';
import { AuthStatus, constants } from '@clerk/backend/internal';
import { eventMethodCalled } from '@clerk/shared/telemetry';
Expand Down Expand Up @@ -115,9 +114,3 @@ export const clerkMiddleware: ClerkMiddleware = (...args: unknown[]) => {
await handler?.(event);
});
};

declare module 'h3' {
interface H3EventContext {
auth: AuthObject;
}
}
Loading