fix(guest): move guest token from URL query to sessionStorage (#21) #28
|
|
@ -158,8 +158,9 @@ describe('GuestCheckoutPage', () => {
|
|||
await vi.waitFor(() => {
|
||||
expect(router.currentRoute.value.name).toBe('guest-payment')
|
||||
expect(router.currentRoute.value.params.orderId).toBe('order-123')
|
||||
expect(router.currentRoute.value.query.token).toBe('token-abc')
|
||||
expect(router.currentRoute.value.query.token).toBeUndefined()
|
||||
expect(router.currentRoute.value.query.plate).toBe('ABC123')
|
||||
expect(sessionStorage.getItem('guestToken')).toBe('token-abc')
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -67,13 +67,20 @@ async function mountPage(
|
|||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
token = 'token-abc',
|
||||
plate = 'ABC123',
|
||||
) {
|
||||
// Store token in sessionStorage as GuestCheckoutPage and GuestOrderPage do
|
||||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
if (token) {
|
||||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
sessionStorage.setItem('guestToken', token)
|
||||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
} else {
|
||||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
sessionStorage.removeItem('guestToken')
|
||||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
}
|
||||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
|
||||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
const pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
const router = createTestRouter()
|
||||
await router.push({
|
||||
name: 'guest-payment',
|
||||
params: { orderId },
|
||||
query: { token, plate },
|
||||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
query: { plate },
|
||||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
})
|
||||
await router.isReady()
|
||||
|
||||
|
|
@ -99,6 +106,7 @@ function setupDefaultMocks() {
|
|||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
describe('GuestPaymentRedirect', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
sessionStorage.clear()
|
||||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
setupDefaultMocks()
|
||||
})
|
||||
|
||||
|
|
|
|||
|
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
hermes
commented
💡 Suggestion: The backward-compat fallback ( 💡 **Suggestion**: The backward-compat fallback (`sessionStorage.getItem('guestToken') || route.query.token`) is untested. Consider adding a test case where `mountPage` is called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.
|
||||
|
|
@ -37,11 +37,14 @@ async function handleSubmit() {
|
|||
letterText.value,
|
||||
email.value.trim(),
|
||||
)
|
||||
// Token rides in the query string so the payment page survives refresh.
|
||||
// Store the guest token in sessionStorage so it does not leak via the URL
|
||||
// query string (browser history, access logs, Referer). sessionStorage
|
||||
// persists across page refreshes within the same tab.
|
||||
sessionStorage.setItem('guestToken', order.guestToken)
|
||||
await router.push({
|
||||
name: 'guest-payment',
|
||||
params: { orderId: order.id },
|
||||
query: { token: order.guestToken, plate: order.plate },
|
||||
query: { plate: order.plate },
|
||||
})
|
||||
} catch {
|
||||
errorMessage.value = 'Kunde inte skapa beställningen. Försök igen senare.'
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
import { fetchGuestOrder, type GuestOrder } from '@/api/guestOrders'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
const token = route.params.token as string
|
||||
|
||||
const order = ref<GuestOrder | null>(null)
|
||||
|
|
@ -45,6 +46,18 @@ onMounted(async () => {
|
|||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
function goToPayment() {
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
if (!order.value) return
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
// Store the guest token in sessionStorage so it does not leak via the URL
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
// query string on the payment page.
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
sessionStorage.setItem('guestToken', token)
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
router.push({
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
name: 'guest-payment',
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
params: { orderId: order.value.id },
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
query: { plate: order.value.plate },
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
})
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
}
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -78,15 +91,7 @@ onMounted(async () => {
|
|||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
</div>
|
||||
|
||||
<p v-if="order.status === 'pending_payment'" class="guest-order__hint">
|
||||
<RouterLink
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
:to="{
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
name: 'guest-payment',
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
params: { orderId: order.id },
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
query: { token, plate: order.plate },
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
}"
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
>
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
Gå till betalningssidan
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
</RouterLink>
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
<a href="#" @click.prevent="goToPayment"> Gå till betalningssidan </a>
|
||||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
</p>
|
||||
|
||||
<div class="guest-order__letter">
|
||||
|
|
|
|||
|
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
hermes
commented
💡 Suggestion: 💡 **Suggestion**: `<a href="#" @click.prevent>` degrades screen-reader semantics (a link to `#` / nowhere). A `<button>` styled to match, or keeping `<RouterLink>` with a custom navigation guard, would preserve accessibility without changing the visual result.
|
||||
|
|
@ -9,7 +9,11 @@ const router = useRouter()
|
|||
|
hermes
commented
💡 Suggestion: Consider 💡 **Suggestion**: Consider `sessionStorage.removeItem('guestToken')` right after `payGuestOrder(token)` resolves, before the `router.push`. The token has been consumed at this point and lingering in sessionStorage only extends the credential's lifetime unnecessarily.
hermes
commented
💡 Suggestion: Consider 💡 **Suggestion**: Consider `sessionStorage.removeItem('guestToken')` right after `payGuestOrder(token)` resolves, before the `router.push`. The token has been consumed at this point and lingering in sessionStorage only extends the credential's lifetime unnecessarily.
|
||||
const route = useRoute()
|
||||
|
||||
const orderId = route.params.orderId as string
|
||||
const token = (route.query.token as string) || ''
|
||||
|
hermes
commented
💡 Suggestion: Consider 💡 **Suggestion**: Consider `sessionStorage.removeItem('guestToken')` right after `payGuestOrder(token)` resolves, before the `router.push`. The token has been consumed at this point and lingering in sessionStorage only extends the credential's lifetime unnecessarily.
|
||||
// Read token from sessionStorage (set by the checkout/order pages) so it
|
||||
|
hermes
commented
💡 Suggestion: Consider 💡 **Suggestion**: Consider `sessionStorage.removeItem('guestToken')` right after `payGuestOrder(token)` resolves, before the `router.push`. The token has been consumed at this point and lingering in sessionStorage only extends the credential's lifetime unnecessarily.
|
||||
// does not leak via the URL query string. Fall back to query.token for
|
||||
|
hermes
commented
💡 Suggestion: Consider 💡 **Suggestion**: Consider `sessionStorage.removeItem('guestToken')` right after `payGuestOrder(token)` resolves, before the `router.push`. The token has been consumed at this point and lingering in sessionStorage only extends the credential's lifetime unnecessarily.
|
||||
// backward compatibility with any existing magic links.
|
||||
|
hermes
commented
💡 Suggestion: Consider 💡 **Suggestion**: Consider `sessionStorage.removeItem('guestToken')` right after `payGuestOrder(token)` resolves, before the `router.push`. The token has been consumed at this point and lingering in sessionStorage only extends the credential's lifetime unnecessarily.
|
||||
const token =
|
||||
|
hermes
commented
💡 Suggestion: Consider 💡 **Suggestion**: Consider `sessionStorage.removeItem('guestToken')` right after `payGuestOrder(token)` resolves, before the `router.push`. The token has been consumed at this point and lingering in sessionStorage only extends the credential's lifetime unnecessarily.
|
||||
sessionStorage.getItem('guestToken') || (route.query.token as string) || ''
|
||||
|
hermes
commented
💡 Suggestion: Consider 💡 **Suggestion**: Consider `sessionStorage.removeItem('guestToken')` right after `payGuestOrder(token)` resolves, before the `router.push`. The token has been consumed at this point and lingering in sessionStorage only extends the credential's lifetime unnecessarily.
|
||||
|
||||
const plate = ref((route.query.plate as string) || '')
|
||||
const swishNumber = ref('')
|
||||
|
|
|
|||
|
hermes
commented
💡 Suggestion: Consider 💡 **Suggestion**: Consider `sessionStorage.removeItem('guestToken')` right after `payGuestOrder(token)` resolves, before the `router.push`. The token has been consumed at this point and lingering in sessionStorage only extends the credential's lifetime unnecessarily.
hermes
commented
💡 Suggestion: Consider 💡 **Suggestion**: Consider `sessionStorage.removeItem('guestToken')` right after `payGuestOrder(token)` resolves, before the `router.push`. The token has been consumed at this point and lingering in sessionStorage only extends the credential's lifetime unnecessarily.
|
||||
💡 Suggestion: The backward-compat fallback (
sessionStorage.getItem('guestToken') || route.query.token) is untested. Consider adding a test case wheremountPageis called with the token in the route query but sessionStorage cleared, to verify the fallback works for old bookmarked URLs.