Skip to content

chore(vue,nuxt): Make initialState prop public and bump dependencies #6132

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

Merged
merged 13 commits into from
Jun 17, 2025
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
6 changes: 6 additions & 0 deletions .changeset/tame-poems-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@clerk/nuxt": patch
"@clerk/vue": patch
---

Make `initialState` prop public and bump `@nuxt/kit` to 3.17.5
24 changes: 16 additions & 8 deletions packages/nextjs/src/__tests__/webhooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ const mockSuccessResponse = {
object: 'event',
} as any;

const mockError = new Error('Missing required Svix headers: svix-id, svix-timestamp, svix-signature');

vi.mock('@clerk/backend/webhooks', () => ({
verifyWebhook: vi.fn().mockImplementation((request: Request) => {
const svixId = request.headers.get('svix-id');
const svixTimestamp = request.headers.get('svix-timestamp');
const svixSignature = request.headers.get('svix-signature');
verifyWebhook: vi.fn().mockImplementation(async (request: any) => {
// Support both Fetch API Request and plain object
const getHeader = (key: string) => {
if (request instanceof Request) {
return request.headers.get(key);
}
return request.headers?.[key];
};

const svixId = getHeader('svix-id');
const svixTimestamp = getHeader('svix-timestamp');
const svixSignature = getHeader('svix-signature');

if (!svixId || !svixTimestamp || !svixSignature) {
throw mockError;
throw new Error('Missing required Svix headers: svix-id, svix-timestamp, svix-signature');
}

return mockSuccessResponse;
Expand Down Expand Up @@ -88,7 +94,9 @@ describe('verifyWebhook', () => {
aborted: false,
} as unknown as NextApiRequest;

await expect(verifyWebhook(mockNextApiRequest)).rejects.toThrow(mockError);
await expect(verifyWebhook(mockNextApiRequest)).rejects.toThrow(
'Missing required Svix headers: svix-id, svix-timestamp, svix-signature',
);
});
});
});
8 changes: 4 additions & 4 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
"@clerk/shared": "workspace:^",
"@clerk/types": "workspace:^",
"@clerk/vue": "workspace:^",
"@nuxt/kit": "^3.16.2",
"@nuxt/schema": "^3.16.2",
"h3": "^1.15.1"
"@nuxt/kit": "^3.17.5",
"@nuxt/schema": "^3.17.5",
"h3": "^1.15.3"
},
"devDependencies": {
"nuxt": "^3.16.2",
"nuxt": "^3.17.5",
"typescript": "catalog:repo"
},
"engines": {
Expand Down
1 change: 1 addition & 0 deletions packages/nuxt/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare module 'nuxt/schema' {
clerk: {
secretKey?: string;
jwtKey?: string;
webhookSigningSecret?: string;
};
}
interface PublicRuntimeConfig {
Expand Down
11 changes: 7 additions & 4 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
updateRuntimeConfig,
} from '@nuxt/kit';

export type ModuleOptions = Without<PluginOptions, 'routerPush' | 'routerReplace' | 'publishableKey'> & {
export type ModuleOptions = Without<
PluginOptions,
'routerPush' | 'routerReplace' | 'publishableKey' | 'initialState'
> & {
publishableKey?: string;
/**
* Skip the automatic server middleware registration. When enabled, you'll need to
Expand Down Expand Up @@ -106,10 +109,10 @@ export default defineNuxtModule<ModuleOptions>({
addTypeTemplate(
{
filename: 'types/clerk.d.ts',
getContents: () => `import type { SignedInAuthObject, SignedOutAuthObject } from '@clerk/backend/internal';
getContents: () => `import type { SessionAuthObject } from '@clerk/backend';
declare module 'h3' {
type AuthObjectHandler = (SignedInAuthObject | SignedOutAuthObject) & {
(): SignedInAuthObject | SignedOutAuthObject;
type AuthObjectHandler = SessionAuthObject & {
(): SessionAuthObject;
Comment on lines +112 to +115
Copy link
Member Author

@wobsoriano wobsoriano Jun 16, 2025

Choose a reason for hiding this comment

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

SessionAuthObject is a new type introduced in machine auth

see token types

}

interface H3EventContext {
Expand Down
4 changes: 3 additions & 1 deletion packages/nuxt/src/runtime/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { setClerkJsLoadingErrorPackageName } from '@clerk/shared/loadClerkJsScript';
import type { InitialState } from '@clerk/types';
import { clerkPlugin } from '@clerk/vue';
import { setErrorThrowerOptions } from '@clerk/vue/internal';
import { defineNuxtPlugin, navigateTo, useRuntimeConfig, useState } from 'nuxt/app';
Expand All @@ -8,14 +9,15 @@ setClerkJsLoadingErrorPackageName(PACKAGE_NAME);

export default defineNuxtPlugin(nuxtApp => {
// SSR-friendly shared state
const initialState = useState('clerk-initial-state', () => undefined);
const initialState = useState<InitialState | undefined>('clerk-initial-state', () => undefined);

if (import.meta.server) {
// Save the initial state from server and pass it to the plugin
initialState.value = nuxtApp.ssrContext?.event.context.__clerk_initial_state;
}

const runtimeConfig = useRuntimeConfig();

nuxtApp.vueApp.use(clerkPlugin, {
...(runtimeConfig.public.clerk ?? {}),
sdkMetadata: {
Expand Down
6 changes: 3 additions & 3 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
},
"devDependencies": {
"@testing-library/vue": "^8.1.0",
"@vitejs/plugin-vue": "^5.2.3",
"@vitejs/plugin-vue": "^5.2.4",
"@vue.ts/tsx-auto-props": "^0.6.0",
"unplugin-vue": "^5.2.1",
"vue": "3.5.13",
"unplugin-vue": "^6.2.0",
"vue": "3.5.16",
"vue-tsc": "^2.2.10"
},
"peerDependencies": {
Expand Down
8 changes: 5 additions & 3 deletions packages/vue/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { inBrowser } from '@clerk/shared/browser';
import { deriveState } from '@clerk/shared/deriveState';
import { loadClerkJsScript, type LoadClerkJsScriptOptions } from '@clerk/shared/loadClerkJsScript';
import type { Clerk, ClientResource, MultiDomainAndOrProxy, Resources, Without } from '@clerk/types';
import type { Clerk, ClientResource, InitialState, MultiDomainAndOrProxy, Resources, Without } from '@clerk/types';
import type { Plugin } from 'vue';
import { computed, ref, shallowRef, triggerRef } from 'vue';

import { ClerkInjectionKey } from './keys';

export type PluginOptions = Without<LoadClerkJsScriptOptions, 'domain' | 'proxyUrl'> & MultiDomainAndOrProxy;
export type PluginOptions = Without<LoadClerkJsScriptOptions, 'domain' | 'proxyUrl'> &
MultiDomainAndOrProxy & {
initialState?: InitialState;
};
Comment on lines +10 to +13
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

initialState leaks into loadClerkJsScript options

pluginOptions now carries initialState, but a few lines below we cast the full object to LoadClerkJsScriptOptions and forward it to loadClerkJsScript:

const options = {
  ...pluginOptions,
  sdkMetadata: pluginOptions.sdkMetadata || SDK_METADATA,
} as LoadClerkJsScriptOptions;

loadClerkJsScript has no concept of initialState; the extra key is silently ignored today but future strict‐mode checks (or external libs doing Object.keys) might fail.

A minimal, type-safe guard:

-const options = {
-  ...pluginOptions,
-  sdkMetadata: pluginOptions.sdkMetadata || SDK_METADATA,
-} as LoadClerkJsScriptOptions;
+const { initialState, ...loadOptions } = pluginOptions;
+const options: LoadClerkJsScriptOptions = {
+  ...loadOptions,
+  sdkMetadata: loadOptions.sdkMetadata || SDK_METADATA,
+};

Keeps runtime payload clean and removes the need for the as cast.

🤖 Prompt for AI Agents
In packages/vue/src/plugin.ts around lines 10 to 13, the PluginOptions type
includes an initialState property that is not part of LoadClerkJsScriptOptions
but is being cast and passed to loadClerkJsScript, causing a type leak. To fix
this, explicitly separate initialState from pluginOptions before passing options
to loadClerkJsScript, ensuring only valid LoadClerkJsScriptOptions keys are
forwarded. Remove the type assertion cast and construct the options object
without initialState to keep the runtime payload clean and maintain type safety.


const SDK_METADATA = {
name: PACKAGE_NAME,
Expand Down Expand Up @@ -35,7 +38,6 @@ const SDK_METADATA = {
*/
export const clerkPlugin: Plugin<[PluginOptions]> = {
install(app, pluginOptions) {
// @ts-expect-error: Internal property for SSR frameworks like Nuxt
const { initialState } = pluginOptions;

const loaded = shallowRef(false);
Expand Down
Loading