From 0cfbb18404d6c4569eff1b1209f8112b1a88d35b Mon Sep 17 00:00:00 2001 From: Manuel Odelain Date: Thu, 14 Mar 2024 22:43:01 +0100 Subject: [PATCH] feat(useRoadizPreview()): use init function --- composables/use-roadiz-preview.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/composables/use-roadiz-preview.ts b/composables/use-roadiz-preview.ts index fa220a7..0334328 100644 --- a/composables/use-roadiz-preview.ts +++ b/composables/use-roadiz-preview.ts @@ -6,10 +6,13 @@ interface UsePreviewState { interface UsePreviewOptions extends UsePreviewState {} export function useRoadizPreview(options?: UsePreviewOptions) { - const state = useState('preview', () => ({ - isActive: false, - token: undefined as string | undefined, - })) + const state = useState('preview', () => { + const route = useRoute() + const token = typeof route.query?.token === 'string' ? route.query.token : undefined + const isActive = !!token && route.query?._preview === '1' + + return { token, isActive } + }) const isActive = computed({ get() {