Skip to content

Commit e2dd40a

Browse files
authored
fix(nuxt): Prevent Nuxt route middlewares from seeing intermediate states during navigation (#6802)
1 parent d6c7bbb commit e2dd40a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.changeset/funny-peaches-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/nuxt": patch
3+
---
4+
5+
Fixed an issue where Nuxt route middleware saw intermediate states during navigation, causing unwanted redirects during sign-in/sign-out flows.

packages/nuxt/src/runtime/plugin.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { clerkPlugin } from '@clerk/vue';
44
import { setErrorThrowerOptions } from '@clerk/vue/internal';
55
import { defineNuxtPlugin, navigateTo, useRuntimeConfig, useState } from 'nuxt/app';
66

7+
// @ts-expect-error: Handled by Nuxt.
8+
import { nextTick } from '#imports';
9+
710
setErrorThrowerOptions({ packageName: PACKAGE_NAME });
811
setClerkJsLoadingErrorPackageName(PACKAGE_NAME);
912

@@ -25,8 +28,16 @@ export default defineNuxtPlugin(nuxtApp => {
2528
version: PACKAGE_VERSION,
2629
environment: process.env.NODE_ENV,
2730
},
28-
routerPush: (to: string) => navigateTo(to),
29-
routerReplace: (to: string) => navigateTo(to, { replace: true }),
31+
routerPush: (to: string) => {
32+
return nextTick(() => {
33+
void navigateTo(to);
34+
});
35+
},
36+
routerReplace: (to: string) => {
37+
return nextTick(() => {
38+
void navigateTo(to, { replace: true });
39+
});
40+
},
3041
initialState: initialState.value,
3142
});
3243
});

0 commit comments

Comments
 (0)