Invite page will now no longer redirect to login #15

Merged
robin merged 1 commits from dev into main 2026-08-31 22:42:24 +02:00
2 changed files with 17 additions and 0 deletions
Showing only changes of commit 1bacc58648 - Show all commits
+15
View File
@@ -140,6 +140,11 @@ describe('useListsStore', () => {
Object.defineProperty(navigator, 'onLine', { value: true, configurable: true })
// sync() is a no-op for anonymous visitors (see lists.ts); these tests
// exercise the authenticated sync path, so seed a logged-in session.
localStorage.setItem('access_token', 'test-access-token')
localStorage.setItem('refresh_token', 'test-refresh-token')
// Default the read endpoints to an empty result so that the pullFromServer()
// step chained onto every sync() call doesn't interfere with unrelated tests.
listsApiMocks.getListsApi.mockResolvedValue([])
@@ -244,6 +249,16 @@ describe('useListsStore', () => {
expect(store.pendingCount).toBe(1)
})
it('does not attempt to sync when logged out, e.g. an anonymous visitor on a public invite link', async () => {
localStorage.removeItem('access_token')
localStorage.removeItem('refresh_token')
const store = useListsStore()
await store.sync()
expect(listsApiMocks.getListsApi).not.toHaveBeenCalled()
})
it('sets a list item completed locally and pushes it via the dedicated endpoint', async () => {
listsApiMocks.createListItemApi.mockResolvedValueOnce({
id: 'server-item-3',
+2
View File
@@ -1,5 +1,6 @@
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { useAuthStore } from '@/stores/auth'
import {
db,
type LocalList,
@@ -438,6 +439,7 @@ export const useListsStore = defineStore('lists', () => {
return ongoingSync
}
if (typeof navigator !== 'undefined' && !navigator.onLine) return
if (!useAuthStore().isAuthenticated) return
ongoingSync = enqueueOperation(() => runSync().then(() => pullFromServer()))
try {