The single axios.ts file becomes a directory with:
- factory.ts — createApiClient + the registerDefaultInterceptors /
registerPortalTokenInterceptors seam (preserves the
TECH-AXIOS-STORE-COUPLING decoupling — no store imports inside)
- default.ts — cookie-authenticated client (organizer + cookie-auth
portal flows; existing 45 call sites resolve unchanged)
- portal-token.ts — Bearer-auth client for the artist-advance /
supplier-intake flows (forward-compatible groundwork; no active
consumers today)
- index.ts — re-exports apiClient + portalApiClient + the register* /
createApiClient surface; the existing `import { apiClient } from
'@/lib/axios'` continues to work directory-resolved.
The bindings plugin (plugins/3.axios-bindings.ts) now wires both
clients with a shared deps base + flavour-specific overrides. The
`getPortalToken` callback returns null until Phase E surfaces
`portalToken` on useAuthStore — no current consumers exercise the
Bearer path, so the null-return is intentional placeholder.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import type { App } from 'vue'
|
|
import {
|
|
apiClient,
|
|
portalApiClient,
|
|
registerDefaultInterceptors,
|
|
registerPortalTokenInterceptors,
|
|
} from '@/lib/axios'
|
|
import { useAuthStore } from '@/stores/useAuthStore'
|
|
import { useImpersonationStore } from '@/stores/useImpersonationStore'
|
|
import { useNotificationStore } from '@/stores/useNotificationStore'
|
|
import { useOrganisationStore } from '@/stores/useOrganisationStore'
|
|
|
|
// Numeric prefix `3.` runs after `2.pinia.ts`, so Pinia is active by
|
|
// the time these store factories resolve. Stores are looked up lazily
|
|
// inside each callback (not eagerly at plugin-init), which keeps the
|
|
// seam tolerant of any future plugin-ordering changes.
|
|
export default function (_: App): void {
|
|
const sharedDeps = {
|
|
notify: (message: string, level: 'error' | 'warning') =>
|
|
useNotificationStore().show(message, level),
|
|
onAuthFail: () => {
|
|
const authStore = useAuthStore()
|
|
if (authStore.isInitialized)
|
|
authStore.handleUnauthorized()
|
|
},
|
|
onImpersonationRevoked: () => {
|
|
useImpersonationStore().clearState()
|
|
window.location.href = '/platform'
|
|
},
|
|
}
|
|
|
|
registerDefaultInterceptors(apiClient, {
|
|
...sharedDeps,
|
|
getActiveOrgId: () => useOrganisationStore().activeOrganisationId,
|
|
getImpersonationTargetUserId: () => useImpersonationStore().targetUserId,
|
|
})
|
|
|
|
registerPortalTokenInterceptors(portalApiClient, {
|
|
...sharedDeps,
|
|
|
|
getPortalToken: () => {
|
|
const authStore = useAuthStore() as unknown as { portalToken?: string | null }
|
|
|
|
return authStore.portalToken ?? null
|
|
},
|
|
})
|
|
}
|