diff --git a/.changeset/shaggy-moose-stare.md b/.changeset/shaggy-moose-stare.md new file mode 100644 index 0000000000..ba6a93912b --- /dev/null +++ b/.changeset/shaggy-moose-stare.md @@ -0,0 +1,6 @@ +--- +'@directus/app': patch +--- + +Fixed an issue that would persist the full screen preview URL as an in-app user's last-page, potentially causing issues +on login diff --git a/app/src/router.ts b/app/src/router.ts index 8beee0a5a8..effd009b1f 100644 --- a/app/src/router.ts +++ b/app/src/router.ts @@ -166,7 +166,7 @@ export const onAfterEach: NavigationHookAfter = (to) => { } trackTimeout = window.setTimeout(() => { - userStore.trackPage(to.fullPath); + userStore.trackPage(to); }, 500); } }; diff --git a/app/src/stores/user.test.ts b/app/src/stores/user.test.ts index 2b07d365aa..2ed56fe09a 100644 --- a/app/src/stores/user.test.ts +++ b/app/src/stores/user.test.ts @@ -2,6 +2,7 @@ import { createTestingPinia } from '@pinia/testing'; import { AxiosRequestConfig } from 'axios'; import { setActivePinia } from 'pinia'; import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; +import type { RouteLocationNormalized } from 'vue-router'; beforeEach(() => { setActivePinia( @@ -149,7 +150,7 @@ describe('actions', () => { vi.spyOn(latencyStore, 'save').mockReturnValue(); const userStore = useUserStore(); - await userStore.trackPage(page); + await userStore.trackPage({ path: page, fullPath: page } as RouteLocationNormalized); expect((userStore.currentUser as User)?.last_page).not.toBe(page); }); @@ -160,7 +161,7 @@ describe('actions', () => { const userStore = useUserStore(); await userStore.hydrate(); - await userStore.trackPage(page); + await userStore.trackPage({ path: page, fullPath: page } as RouteLocationNormalized); expect((userStore.currentUser as User).last_page).toBe(page); }); diff --git a/app/src/stores/user.ts b/app/src/stores/user.ts index 1ff8abc418..79a85cfc86 100644 --- a/app/src/stores/user.ts +++ b/app/src/stores/user.ts @@ -1,9 +1,10 @@ import api from '@/api'; import { useLatencyStore } from '@/stores/latency'; -import { User } from '@directus/types'; import { userName } from '@/utils/user-name'; +import { User } from '@directus/types'; import { merge } from 'lodash'; import { defineStore } from 'pinia'; +import type { RouteLocationNormalized } from 'vue-router'; type ShareUser = { share: string; @@ -72,13 +73,22 @@ export const useUserStore = defineStore({ // Do nothing } }, - async trackPage(page: string) { + async trackPage(to: RouteLocationNormalized) { + /** + * We don't want to track the full screen preview from live previews as part of the user's + * last page, as that'll cause a fresh login to navigate to the full screen preview where + * you can't navigate away from #19160 + */ + if (to.path.endsWith('/preview')) { + return; + } + const latencyStore = useLatencyStore(); const start = performance.now(); await api.patch(`/users/me/track/page`, { - last_page: page, + last_page: to.fullPath, }); const end = performance.now(); @@ -89,7 +99,7 @@ export const useUserStore = defineStore({ }); if (this.currentUser && !('share' in this.currentUser)) { - this.currentUser.last_page = page; + this.currentUser.last_page = to.fullPath; } }, },