/** * Magic link helper for payment-return pages. * * The customer store now owns all token decoding (see stores/customer.js: * `hydrateFromToken`). This composable is a thin read-through so the * payment pages can render `v-if="auth.authenticated"` without caring * about where the session came from (magic-link URL vs. existing nav). * * The router guard already calls `store.hydrateFromToken()` before these * pages mount, so by the time this runs the store is either hydrated or * still empty — no extra decoding needed here. */ import { useRoute } from 'vue-router' import { useCustomerStore } from 'src/stores/customer' export function useMagicToken () { const route = useRoute() const store = useCustomerStore() // `expired` is a hint for the UI: "you arrived here with a token but we // couldn't use it". Approximated by: URL had a token (route.query or the // raw hash) but the store is still empty. const urlHadToken = !!route.query.token || (typeof window !== 'undefined' && window.location.hash.includes('token=')) const authenticated = !!store.customerId const expired = urlHadToken && !authenticated return { authenticated, expired, customerId: store.customerId } }