diff --git a/src/app/components/ClientCard/OneTimeLink.vue b/src/app/components/ClientCard/OneTimeLink.vue index 4973b41e..9ace22f6 100644 --- a/src/app/components/ClientCard/OneTimeLink.vue +++ b/src/app/components/ClientCard/OneTimeLink.vue @@ -22,7 +22,7 @@ onMounted(() => { new Date(props.client.oneTimeLink.expiresAt).getTime() - Date.now(); if (timeLeft <= 0) { - path.value = `${document.location.protocol}//${document.location.host}/cnf/${props.client.oneTimeLink.oneTimeLink} (00:00)`; + path.value = `${props.client.oneTimeConfigUrl} (00:00)`; return; } @@ -39,7 +39,7 @@ onMounted(() => { date.setMinutes(minutes); date.setSeconds(seconds); - path.value = `${document.location.protocol}//${document.location.host}/cnf/${props.client.oneTimeLink.oneTimeLink} (${formatter.format(date)})`; + path.value = `${props.client.oneTimeConfigUrl} (${formatter.format(date)})`; }, 1000); }); diff --git a/src/app/components/ClientCard/OneTimeLinkBtn.vue b/src/app/components/ClientCard/OneTimeLinkBtn.vue index aa943627..e26b37bf 100644 --- a/src/app/components/ClientCard/OneTimeLinkBtn.vue +++ b/src/app/components/ClientCard/OneTimeLinkBtn.vue @@ -14,10 +14,6 @@ const props = defineProps<{ client: LocalClient }>(); const clientsStore = useClientsStore(); const toast = useToast(); const { copy, copied, isSupported } = useClipboard(); -const oneTimeLink = computed( - () => - `${document.location.protocol}//${document.location.host}/cnf/${props.client.oneTimeLink.oneTimeLink}` -); const _showOneTimeLink = useSubmit( `/api/client/${props.client.id}/generateOneTimeLink`, @@ -42,7 +38,17 @@ async function copyOneTimeLink() { return; } await nextTick(); - await copy(oneTimeLink.value); + + if (!props.client.oneTimeConfigUrl) { + toast.showToast({ + type: 'error', + message: $t('copy.error'), + }); + return; + } + + await copy(props.client.oneTimeConfigUrl); + if (!copied.value) { toast.showToast({ type: 'error', diff --git a/src/app/stores/clients.ts b/src/app/stores/clients.ts index e9c58fa5..3e08eba5 100644 --- a/src/app/stores/clients.ts +++ b/src/app/stores/clients.ts @@ -15,6 +15,7 @@ export type LocalClient = WGClientReturn & { export type ClientPersist = { transferRxHistory: number[]; + oneTimeConfigUrl?: string; transferRxPrevious: number; transferRxCurrent: number; transferRxSeries: { name: string; data: number[] }[]; @@ -59,6 +60,7 @@ export const useClientsStore = defineStore('Clients', () => { transferTxCurrent: 0, transferRxSeries: [], transferTxSeries: [], + oneTimeConfigUrl: '', }; } @@ -110,6 +112,10 @@ export const useClientsStore = defineStore('Clients', () => { ); } + if (client.oneTimeLink !== null) { + clientPersist.oneTimeConfigUrl = `${document?.location?.protocol}//${document?.location?.host}/cnf/${client.oneTimeLink.oneTimeLink}`; + } + return { ...client, avatar, @@ -122,6 +128,7 @@ export const useClientsStore = defineStore('Clients', () => { transferRxCurrent: clientPersist.transferRxCurrent, hoverTx: clientPersist.hoverTx, hoverRx: clientPersist.hoverRx, + oneTimeConfigUrl: clientPersist.oneTimeConfigUrl, }; });