refactor(axios): split lib/axios.ts into factory + default + portal-token instances
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>
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import type { App } from 'vue'
|
||||
import { apiClient, registerInterceptors } from '@/lib/axios'
|
||||
import {
|
||||
apiClient,
|
||||
portalApiClient,
|
||||
registerDefaultInterceptors,
|
||||
registerPortalTokenInterceptors,
|
||||
} from '@/lib/axios'
|
||||
import { useAuthStore } from '@/stores/useAuthStore'
|
||||
import { useImpersonationStore } from '@/stores/useImpersonationStore'
|
||||
import { useNotificationStore } from '@/stores/useNotificationStore'
|
||||
@@ -10,10 +15,9 @@ import { useOrganisationStore } from '@/stores/useOrganisationStore'
|
||||
// inside each callback (not eagerly at plugin-init), which keeps the
|
||||
// seam tolerant of any future plugin-ordering changes.
|
||||
export default function (_: App): void {
|
||||
registerInterceptors(apiClient, {
|
||||
getActiveOrgId: () => useOrganisationStore().activeOrganisationId,
|
||||
getImpersonationTargetUserId: () => useImpersonationStore().targetUserId,
|
||||
notify: (message, level) => useNotificationStore().show(message, level),
|
||||
const sharedDeps = {
|
||||
notify: (message: string, level: 'error' | 'warning') =>
|
||||
useNotificationStore().show(message, level),
|
||||
onAuthFail: () => {
|
||||
const authStore = useAuthStore()
|
||||
if (authStore.isInitialized)
|
||||
@@ -23,5 +27,21 @@ export default function (_: App): void {
|
||||
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
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user